From 8de27637cc3eebb3fcba0c8a2ceafb36605fed4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 16 Jul 2022 13:13:03 +0200 Subject: [PATCH 1/2] Avoid using deprecated functions from clue/reactphp-block --- tests/FdServerTest.php | 3 +- tests/FixedUriConnectorTest.php | 1 - tests/FunctionalConnectorTest.php | 17 +++++---- tests/FunctionalSecureServerTest.php | 54 ++++++++++++++-------------- tests/FunctionalTcpServerTest.php | 27 +++++++------- tests/HappyEyeBallsConnectorTest.php | 12 +++++-- tests/IntegrationTest.php | 45 ++++++++++++----------- tests/LimitingServerTest.php | 7 ++-- tests/SecureIntegrationTest.php | 33 +++++++++-------- tests/ServerTest.php | 15 ++++---- tests/SocketServerTest.php | 15 ++++---- tests/TcpConnectorTest.php | 19 +++++----- tests/TcpServerTest.php | 5 ++- tests/TestCase.php | 9 +++-- tests/TimeoutConnectorTest.php | 9 +++-- tests/TimerSpeedUpEventLoop.php | 4 --- tests/UnixServerTest.php | 3 +- 17 files changed, 132 insertions(+), 146 deletions(-) diff --git a/tests/FdServerTest.php b/tests/FdServerTest.php index e944eb9e..21c38c1b 100644 --- a/tests/FdServerTest.php +++ b/tests/FdServerTest.php @@ -2,7 +2,6 @@ namespace React\Tests\Socket; -use Clue\React\Block; use React\Promise\Promise; use React\Socket\ConnectionInterface; use React\Socket\FdServer; @@ -322,7 +321,7 @@ public function testServerEmitsConnectionEventForNewConnection() $server->on('connection', $resolve); }); - $connection = Block\await($promise, null, 1.0); + $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, 1.0)); /** * @var ConnectionInterface $connection diff --git a/tests/FixedUriConnectorTest.php b/tests/FixedUriConnectorTest.php index f42d74fe..bdc1d770 100644 --- a/tests/FixedUriConnectorTest.php +++ b/tests/FixedUriConnectorTest.php @@ -3,7 +3,6 @@ namespace React\Tests\Socket; use React\Socket\FixedUriConnector; -use React\Tests\Socket\TestCase; class FixedUriConnectorTest extends TestCase { diff --git a/tests/FunctionalConnectorTest.php b/tests/FunctionalConnectorTest.php index 767b92f0..b0c4bb5f 100644 --- a/tests/FunctionalConnectorTest.php +++ b/tests/FunctionalConnectorTest.php @@ -2,7 +2,6 @@ namespace React\Tests\Socket; -use Clue\React\Block; use React\EventLoop\Loop; use React\Promise\Deferred; use React\Socket\ConnectionInterface; @@ -24,7 +23,7 @@ public function connectionToTcpServerShouldSucceedWithLocalhost() $connector = new Connector(array()); - $connection = Block\await($connector->connect('localhost:9998'), null, self::TIMEOUT); + $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('localhost:9998'), self::TIMEOUT)); $server->close(); @@ -63,11 +62,11 @@ public function testConnectTwiceWithoutHappyEyeBallsOnlySendsSingleDnsQueryDueTo fclose($client); }); - $connection = Block\await($connector->connect('example.com:80')); + $connection = \Clue\React\Block\await($connector->connect('example.com:80')); $connection->close(); $this->assertEquals(1, $received); - $connection = Block\await($connector->connect('example.com:80')); + $connection = \Clue\React\Block\await($connector->connect('example.com:80')); $connection->close(); $this->assertEquals(1, $received); @@ -85,7 +84,7 @@ public function connectionToRemoteTCP4n6ServerShouldResultInOurIP() $connector = new Connector(array('happy_eyeballs' => true)); - $ip = Block\await($this->request('dual.tlund.se', $connector), null, self::TIMEOUT); + $ip = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->request('dual.tlund.se', $connector), self::TIMEOUT)); $this->assertNotFalse(inet_pton($ip)); } @@ -99,7 +98,7 @@ public function connectionToRemoteTCP4ServerShouldResultInOurIP() $connector = new Connector(array('happy_eyeballs' => true)); try { - $ip = Block\await($this->request('ipv4.tlund.se', $connector), null, self::TIMEOUT); + $ip = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->request('ipv4.tlund.se', $connector), self::TIMEOUT)); } catch (\Exception $e) { $this->checkIpv4(); throw $e; @@ -118,7 +117,7 @@ public function connectionToRemoteTCP6ServerShouldResultInOurIP() $connector = new Connector(array('happy_eyeballs' => true)); try { - $ip = Block\await($this->request('ipv6.tlund.se', $connector), null, self::TIMEOUT); + $ip = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->request('ipv6.tlund.se', $connector), self::TIMEOUT)); } catch (\Exception $e) { $this->checkIpv6(); throw $e; @@ -151,11 +150,11 @@ public function testCancelPendingTlsConnectionDuringTlsHandshakeShouldCloseTcpCo }); }); - Block\await($deferred->promise(), null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($deferred->promise(), self::TIMEOUT)); $server->close(); try { - Block\await($promise, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->fail(); } catch (\Exception $e) { $this->assertInstanceOf('RuntimeException', $e); diff --git a/tests/FunctionalSecureServerTest.php b/tests/FunctionalSecureServerTest.php index d81040e6..071daf29 100644 --- a/tests/FunctionalSecureServerTest.php +++ b/tests/FunctionalSecureServerTest.php @@ -2,8 +2,6 @@ namespace React\Tests\Socket; -use Clue\React\Block; -use Evenement\EventEmitterInterface; use React\Promise\Promise; use React\Socket\ConnectionInterface; use React\Socket\SecureConnector; @@ -39,7 +37,7 @@ public function testClientCanConnectToServer() $promise = $connector->connect($server->getAddress()); /* @var ConnectionInterface $client */ - $client = Block\await($promise, null, self::TIMEOUT); + $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $client); $this->assertEquals($server->getAddress(), $client->getRemoteAddress()); @@ -68,7 +66,7 @@ public function testClientUsesTls13ByDefaultWhenSupportedByOpenSSL() $promise = $connector->connect($server->getAddress()); /* @var ConnectionInterface $client */ - $client = Block\await($promise, null, self::TIMEOUT); + $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\Connection', $client); $this->assertTrue(isset($client->stream)); @@ -107,7 +105,7 @@ public function testClientUsesTls12WhenCryptoMethodIsExplicitlyConfiguredByClien $promise = $connector->connect($server->getAddress()); /* @var ConnectionInterface $client */ - $client = Block\await($promise, null, self::TIMEOUT); + $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\Connection', $client); $this->assertTrue(isset($client->stream)); @@ -138,7 +136,7 @@ public function testClientUsesTls12WhenCryptoMethodIsExplicitlyConfiguredByServe $promise = $connector->connect($server->getAddress()); /* @var ConnectionInterface $client */ - $client = Block\await($promise, null, self::TIMEOUT); + $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\Connection', $client); $this->assertTrue(isset($client->stream)); @@ -170,7 +168,7 @@ public function testClientUsesTls10WhenCryptoMethodIsExplicitlyConfiguredByClien /* @var ConnectionInterface $client */ try { - $client = Block\await($promise, null, self::TIMEOUT); + $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\RuntimeException $e) { // legacy TLS 1.0 would be considered insecure by today's standards, so skip test if connection fails // OpenSSL error messages are version/platform specific @@ -212,7 +210,7 @@ public function testServerEmitsConnectionForClientConnection() // await both client and server side end of connection /* @var ConnectionInterface[] $both */ - $both = Block\awaitAll(array($peer, $client), null, self::TIMEOUT); + $both = \Clue\React\Block\await(\React\Promise\Timer\timeout(\React\Promise\all(array($peer, $client)), self::TIMEOUT)); // both ends of the connection are represented by different instances of ConnectionInterface $this->assertCount(2, $both); @@ -252,7 +250,7 @@ public function testClientEmitsDataEventOnceForDataWrittenFromServer() }, $reject); }); - $data = Block\await($promise, null, self::TIMEOUT); + $data = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals('foo', $data); @@ -293,7 +291,7 @@ public function testWritesDataInMultipleChunksToConnection() }, $reject); }); - $received = Block\await($promise, null, self::TIMEOUT); + $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(400000, $received); @@ -334,7 +332,7 @@ public function testWritesMoreDataInMultipleChunksToConnection() }, $reject); }); - $received = Block\await($promise, null, self::TIMEOUT); + $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(2000000, $received); @@ -367,7 +365,7 @@ public function testEmitsDataFromConnection() $connection->write('foo'); }); - $data = Block\await($promise, null, self::TIMEOUT); + $data = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals('foo', $data); @@ -407,7 +405,7 @@ public function testEmitsDataInMultipleChunksFromConnection() $connection->write(str_repeat('*', 400000)); }); - $received = Block\await($promise, null, self::TIMEOUT); + $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(400000, $received); @@ -449,7 +447,7 @@ public function testPipesDataBackInMultipleChunksFromConnection() }, $reject); }); - $received = Block\await($promise, null, self::TIMEOUT); + $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(400000, $received); @@ -479,7 +477,7 @@ public function testEmitsConnectionForNewTlsv11Connection() )); $promise = $connector->connect($server->getAddress()); - Block\await($promise, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $server->close(); $promise->then(function (ConnectionInterface $connection) { @@ -510,7 +508,7 @@ public function testEmitsErrorForClientWithTlsVersionMismatch() $this->setExpectedException('RuntimeException', 'handshake'); try { - Block\await($promise, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -536,7 +534,7 @@ public function testServerEmitsConnectionForNewConnectionWithEncryptedCertificat )); $connector->connect($server->getAddress()); - $connection = Block\await($peer, null, self::TIMEOUT); + $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $connection); @@ -559,7 +557,7 @@ public function testClientRejectsWithErrorForServerWithInvalidCertificate() $this->setExpectedException('RuntimeException', 'handshake'); try { - Block\await($promise, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -589,7 +587,7 @@ public function testServerEmitsErrorForClientWithInvalidCertificate() $this->setExpectedException('RuntimeException', 'handshake'); try { - Block\await($peer, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -618,7 +616,7 @@ public function testEmitsErrorForServerWithEncryptedCertificateMissingPassphrase $this->setExpectedException('RuntimeException', 'handshake'); try { - Block\await($promise, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -648,7 +646,7 @@ public function testEmitsErrorForServerWithEncryptedCertificateWithInvalidPassph $this->setExpectedException('RuntimeException', 'handshake'); try { - Block\await($promise, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -671,7 +669,7 @@ public function testEmitsErrorForConnectionWithPeerVerification() $promise = $connector->connect($server->getAddress()); $promise->then(null, $this->expectCallableOnce()); - Block\await($errorEvent, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); $server->close(); } @@ -696,7 +694,7 @@ public function testEmitsErrorIfConnectionIsCancelled() $promise->cancel(); $promise->then(null, $this->expectCallableOnce()); - Block\await($errorEvent, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); $server->close(); } @@ -717,7 +715,7 @@ public function testEmitsErrorIfConnectionIsClosedBeforeHandshake() $stream->close(); }); - $error = Block\await($errorEvent, null, self::TIMEOUT); + $error = \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); // Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshake (ECONNRESET) $this->assertInstanceOf('RuntimeException', $error); @@ -745,7 +743,7 @@ public function testEmitsErrorIfConnectionIsClosedWithIncompleteHandshake() $stream->end("\x1e"); }); - $error = Block\await($errorEvent, null, self::TIMEOUT); + $error = \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); // Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshake (ECONNRESET) $this->assertInstanceOf('RuntimeException', $error); @@ -769,7 +767,7 @@ public function testEmitsNothingIfPlaintextConnectionIsIdle() $connector = new TcpConnector(); $promise = $connector->connect(str_replace('tls://', '', $server->getAddress())); - $connection = Block\await($promise, null, self::TIMEOUT); + $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $connection); $server->close(); @@ -794,7 +792,7 @@ public function testEmitsErrorIfConnectionIsHttpInsteadOfSecureHandshake() $stream->write("GET / HTTP/1.0\r\n\r\n"); }); - $error = Block\await($errorEvent, null, self::TIMEOUT); + $error = \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); $this->assertInstanceOf('RuntimeException', $error); @@ -823,7 +821,7 @@ public function testEmitsErrorIfConnectionIsUnknownProtocolInsteadOfSecureHandsh $stream->write("Hello world!\n"); }); - $error = Block\await($errorEvent, null, self::TIMEOUT); + $error = \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); $this->assertInstanceOf('RuntimeException', $error); diff --git a/tests/FunctionalTcpServerTest.php b/tests/FunctionalTcpServerTest.php index 0965f90d..b3260da5 100644 --- a/tests/FunctionalTcpServerTest.php +++ b/tests/FunctionalTcpServerTest.php @@ -2,7 +2,6 @@ namespace React\Tests\Socket; -use Clue\React\Block; use React\Promise\Promise; use React\Socket\ConnectionInterface; use React\Socket\TcpConnector; @@ -26,7 +25,7 @@ public function testEmitsConnectionForNewConnection() $promise->then($this->expectCallableOnce()); - Block\await($peer, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); @@ -46,7 +45,7 @@ public function testEmitsNoConnectionForNewConnectionWhenPaused() $promise->then($this->expectCallableOnce()); - Block\await($promise, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } public function testConnectionForNewConnectionWhenResumedAfterPause() @@ -65,7 +64,7 @@ public function testConnectionForNewConnectionWhenResumedAfterPause() $promise->then($this->expectCallableOnce()); - Block\await($peer, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); $promise->then(function (ConnectionInterface $connection) { @@ -87,7 +86,7 @@ public function testEmitsConnectionWithRemoteIp() $promise->then($this->expectCallableOnce()); - $peer = Block\await($peer, null, self::TIMEOUT); + $peer = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertContainsString('127.0.0.1:', $peer); @@ -113,7 +112,7 @@ public function testEmitsConnectionWithLocalIp() $promise->then($this->expectCallableOnce()); - $local = Block\await($peer, null, self::TIMEOUT); + $local = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertContainsString('127.0.0.1:', $local); $this->assertEquals($server->getAddress(), $local); @@ -142,7 +141,7 @@ public function testEmitsConnectionWithLocalIpDespiteListeningOnAll() $promise->then($this->expectCallableOnce()); - $local = Block\await($peer, null, self::TIMEOUT); + $local = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertContainsString('127.0.0.1:', $local); @@ -168,7 +167,7 @@ public function testEmitsConnectionWithRemoteIpAfterConnectionIsClosedByPeer() $connection->end(); }); - $peer = Block\await($peer, null, self::TIMEOUT); + $peer = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertContainsString('127.0.0.1:', $peer); @@ -190,7 +189,7 @@ public function testEmitsConnectionWithRemoteNullAddressAfterConnectionIsClosedB $promise->then($this->expectCallableOnce()); - $peer = Block\await($peer, null, self::TIMEOUT); + $peer = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertNull($peer); @@ -216,7 +215,7 @@ public function testEmitsConnectionEvenIfClientConnectionIsCancelled() $promise->then(null, $this->expectCallableOnce()); - Block\await($peer, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); } @@ -240,7 +239,7 @@ public function testEmitsConnectionForNewIpv6Connection() $promise->then($this->expectCallableOnce()); - Block\await($peer, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); $promise->then(function (ConnectionInterface $connection) { @@ -267,7 +266,7 @@ public function testEmitsConnectionWithRemoteIpv6() $promise->then($this->expectCallableOnce()); - $peer = Block\await($peer, null, self::TIMEOUT); + $peer = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertContainsString('[::1]:', $peer); @@ -296,7 +295,7 @@ public function testEmitsConnectionWithLocalIpv6() $promise->then($this->expectCallableOnce()); - $local = Block\await($peer, null, self::TIMEOUT); + $local = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertContainsString('[::1]:', $local); $this->assertEquals($server->getAddress(), $local); @@ -361,7 +360,7 @@ public function testEmitsConnectionWithInheritedContextOptions() $promise->then($this->expectCallableOnce()); - $all = Block\await($peer, null, self::TIMEOUT); + $all = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertEquals(array('socket' => array('backlog' => 4)), $all); diff --git a/tests/HappyEyeBallsConnectorTest.php b/tests/HappyEyeBallsConnectorTest.php index 6a26fd63..aeceae54 100644 --- a/tests/HappyEyeBallsConnectorTest.php +++ b/tests/HappyEyeBallsConnectorTest.php @@ -7,7 +7,6 @@ use React\Promise; use React\Promise\Deferred; use React\Socket\HappyEyeBallsConnector; -use Clue\React\Block; class HappyEyeBallsConnectorTest extends TestCase { @@ -63,7 +62,10 @@ public function testHappyFlow() $promise = $this->connector->connect('example.com:80'); $first->resolve(array('1.2.3.4')); - $resolvedConnection = Block\await($promise, $this->loop); + $resolvedConnection = null; + $promise->then(function ($value) use (&$resolvedConnection) { + $resolvedConnection = $value; + }); self::assertSame($connection, $resolvedConnection); } @@ -89,7 +91,11 @@ public function testThatAnyOtherPendingConnectionAttemptsWillBeCanceledOnceAConn $promise = $this->connector->connect('example.com:80'); - $resolvedConnection = Block\await($promise, $this->loop); + $this->loop->run(); + $resolvedConnection = null; + $promise->then(function ($value) use (&$resolvedConnection) { + $resolvedConnection = $value; + }); self::assertSame($connection, $resolvedConnection); } diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index faa91294..9e4c1c77 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -2,7 +2,6 @@ namespace React\Tests\Socket; -use Clue\React\Block; use React\Dns\Resolver\Factory as ResolverFactory; use React\Socket\Connector; use React\Socket\DnsConnector; @@ -19,7 +18,7 @@ public function gettingStuffFromGoogleShouldWork() { $connector = new Connector(array()); - $conn = Block\await($connector->connect('google.com:80')); + $conn = \Clue\React\Block\await($connector->connect('google.com:80')); $this->assertContainsString(':80', $conn->getRemoteAddress()); $this->assertNotEquals('google.com:80', $conn->getRemoteAddress()); @@ -40,7 +39,7 @@ public function gettingEncryptedStuffFromGoogleShouldWork() $secureConnector = new Connector(array()); - $conn = Block\await($secureConnector->connect('tls://google.com:443')); + $conn = \Clue\React\Block\await($secureConnector->connect('tls://google.com:443')); $conn->write("GET / HTTP/1.0\r\n\r\n"); @@ -66,7 +65,7 @@ public function gettingEncryptedStuffFromGoogleShouldWorkIfHostIsResolvedFirst() $dns ); - $conn = Block\await($connector->connect('google.com:443')); + $conn = \Clue\React\Block\await($connector->connect('google.com:443')); $conn->write("GET / HTTP/1.0\r\n\r\n"); @@ -80,7 +79,7 @@ public function gettingPlaintextStuffFromEncryptedGoogleShouldNotWork() { $connector = new Connector(array()); - $conn = Block\await($connector->connect('google.com:443')); + $conn = \Clue\React\Block\await($connector->connect('google.com:443')); $this->assertContainsString(':443', $conn->getRemoteAddress()); $this->assertNotEquals('google.com:443', $conn->getRemoteAddress()); @@ -106,7 +105,7 @@ public function testConnectingFailsIfConnectorUsesInvalidDnsResolverAddress() )); $this->setExpectedException('RuntimeException'); - Block\await($connector->connect('google.com:80'), null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('google.com:80'), self::TIMEOUT)); } public function testCancellingPendingConnectionWithoutTimeoutShouldNotCreateAnyGarbageReferences() @@ -163,11 +162,11 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect connection refused error - Block\sleep(0.01); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - Block\sleep(0.2); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.2)); if ($wait) { - Block\sleep(2.0); + \Clue\React\Block\await(\React\Promise\Timer\sleep(2.0)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -198,9 +197,9 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect a connection timeout error - Block\sleep(0.01); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - Block\sleep(0.2); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.2)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -230,9 +229,9 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect a connection timeout error - Block\sleep(0.01); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - Block\sleep(0.2); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.2)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -262,11 +261,11 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect a DNS error - Block\sleep(0.01); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - Block\sleep(0.2); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.2)); if ($wait) { - Block\sleep(2.0); + \Clue\React\Block\await(\React\Promise\Timer\sleep(2.0)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -304,11 +303,11 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect a TLS error - Block\sleep(0.1); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - Block\sleep(0.4); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.4)); if ($wait) { - Block\sleep(self::TIMEOUT - 0.5); + \Clue\React\Block\await(\React\Promise\Timer\sleep(self::TIMEOUT - 0.5)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -333,7 +332,7 @@ function ($conn) { $conn->close(); } ); - Block\await($promise, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); unset($promise); $this->assertEquals(0, gc_collect_cycles()); @@ -346,7 +345,7 @@ public function testConnectingFailsIfTimeoutIsTooSmall() )); $this->setExpectedException('RuntimeException'); - Block\await($connector->connect('google.com:80'), null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('google.com:80'), self::TIMEOUT)); } public function testSelfSignedRejectsIfVerificationIsEnabled() @@ -362,7 +361,7 @@ public function testSelfSignedRejectsIfVerificationIsEnabled() )); $this->setExpectedException('RuntimeException'); - Block\await($connector->connect('tls://self-signed.badssl.com:443'), null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('tls://self-signed.badssl.com:443'), self::TIMEOUT)); } public function testSelfSignedResolvesIfVerificationIsDisabled() @@ -377,7 +376,7 @@ public function testSelfSignedResolvesIfVerificationIsDisabled() ) )); - $conn = Block\await($connector->connect('tls://self-signed.badssl.com:443'), null, self::TIMEOUT); + $conn = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('tls://self-signed.badssl.com:443'), self::TIMEOUT)); $conn->close(); // if we reach this, then everything is good diff --git a/tests/LimitingServerTest.php b/tests/LimitingServerTest.php index 119fba40..53d3a471 100644 --- a/tests/LimitingServerTest.php +++ b/tests/LimitingServerTest.php @@ -2,7 +2,6 @@ namespace React\Tests\Socket; -use Clue\React\Block; use React\Promise\Promise; use React\Socket\ConnectionInterface; use React\Socket\LimitingServer; @@ -157,7 +156,7 @@ public function testSocketDisconnectionWillRemoveFromList() }); }); - Block\await($peer, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertEquals(array(), $server->getConnections()); @@ -178,7 +177,7 @@ public function testPausingServerWillEmitOnlyOneButAcceptTwoConnectionsDueToOper $first = stream_socket_client($server->getAddress()); $second = stream_socket_client($server->getAddress()); - Block\await($peer, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); fclose($first); fclose($second); @@ -208,7 +207,7 @@ public function testPausingServerWillEmitTwoConnectionsFromBacklog() $second = stream_socket_client($server->getAddress()); fclose($second); - Block\await($peer, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); } diff --git a/tests/SecureIntegrationTest.php b/tests/SecureIntegrationTest.php index 5cf741cb..8d6d1829 100644 --- a/tests/SecureIntegrationTest.php +++ b/tests/SecureIntegrationTest.php @@ -2,15 +2,14 @@ namespace React\Tests\Socket; -use React\Socket\TcpServer; -use React\Socket\SecureServer; -use React\Socket\TcpConnector; -use React\Socket\SecureConnector; -use Clue\React\Block; -use React\Promise\Promise; use Evenement\EventEmitterInterface; use React\Promise\Deferred; +use React\Promise\Promise; use React\Socket\ConnectionInterface; +use React\Socket\SecureConnector; +use React\Socket\SecureServer; +use React\Socket\TcpConnector; +use React\Socket\TcpServer; class SecureIntegrationTest extends TestCase { @@ -50,7 +49,7 @@ public function tearDownServer() public function testConnectToServer() { - $client = Block\await($this->connector->connect($this->address), null, self::TIMEOUT); + $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ $client->close(); @@ -65,7 +64,7 @@ public function testConnectToServerEmitsConnection() $promiseClient = $this->connector->connect($this->address); - list($_, $client) = Block\awaitAll(array($promiseServer, $promiseClient), null, self::TIMEOUT); + list($_, $client) = \Clue\React\Block\await(\React\Promise\Timer\timeout(\React\Promise\all(array($promiseServer, $promiseClient)), self::TIMEOUT)); /* @var $client ConnectionInterface */ $client->close(); @@ -81,13 +80,13 @@ public function testSendSmallDataToServerReceivesOneChunk() }); }); - $client = Block\await($this->connector->connect($this->address), null, self::TIMEOUT); + $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ $client->write('hello'); // await server to report one "data" event - $data = Block\await($received->promise(), null, self::TIMEOUT); + $data = \Clue\React\Block\await(\React\Promise\Timer\timeout($received->promise(), self::TIMEOUT)); $client->close(); @@ -122,14 +121,14 @@ public function testSendDataWithEndToServerReceivesAllData() }); }); - $client = Block\await($this->connector->connect($this->address), null, self::TIMEOUT); + $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ $data = str_repeat('a', 200000); $client->end($data); // await server to report connection "close" event - $received = Block\await($disconnected->promise(), null, self::TIMEOUT); + $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($disconnected->promise(), self::TIMEOUT)); $this->assertEquals(strlen($data), strlen($received)); $this->assertEquals($data, $received); @@ -157,7 +156,7 @@ public function testSendDataWithoutEndingToServerReceivesAllData() $connection->write($data); }); - $received = Block\await($promise, null, self::TIMEOUT); + $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(strlen($data), strlen($received)); $this->assertEquals($data, $received); @@ -173,12 +172,12 @@ public function testConnectToServerWhichSendsSmallDataReceivesOneChunk() $peer->write('hello'); }); - $client = Block\await($this->connector->connect($this->address), null, self::TIMEOUT); + $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ // await client to report one "data" event $receive = $this->createPromiseForEvent($client, 'data', $this->expectCallableOnceWith('hello')); - Block\await($receive, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($receive, self::TIMEOUT)); $client->close(); } @@ -190,7 +189,7 @@ public function testConnectToServerWhichSendsDataWithEndReceivesAllData() $peer->end($data); }); - $client = Block\await($this->connector->connect($this->address), null, self::TIMEOUT); + $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ // await data from client until it closes @@ -221,7 +220,7 @@ public function testConnectToServerWhichSendsDataWithoutEndingReceivesAllData() }, $reject); }); - $received = Block\await($promise, null, self::TIMEOUT); + $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(strlen($data), $received); diff --git a/tests/ServerTest.php b/tests/ServerTest.php index 7c6af61d..0005ab0f 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -2,7 +2,6 @@ namespace React\Tests\Socket; -use Clue\React\Block; use React\Promise\Promise; use React\Socket\ConnectionInterface; use React\Socket\Server; @@ -53,7 +52,7 @@ public function testConstructorCreatesExpectedTcpServer() $promise = $connector->connect($server->getAddress()); $promise->then($this->expectCallableOnce(), $this->expectCallableNever()); - $connection = Block\await($connector->connect($server->getAddress()), null, self::TIMEOUT); + $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect($server->getAddress()), self::TIMEOUT)); $server->close(); $promise->then(function (ConnectionInterface $connection) { @@ -76,7 +75,7 @@ public function testConstructorCreatesExpectedUnixServer() $connector->connect($server->getAddress()) ->then($this->expectCallableOnce(), $this->expectCallableNever()); - $connection = Block\await($connector->connect($server->getAddress()), null, self::TIMEOUT); + $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect($server->getAddress()), self::TIMEOUT)); $connection->close(); $server->close(); @@ -128,7 +127,7 @@ public function testEmitsConnectionForNewConnection() $client = stream_socket_client($server->getAddress()); - Block\await($peer, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); } @@ -141,7 +140,7 @@ public function testDoesNotEmitConnectionForNewConnectionToPausedServer() $client = stream_socket_client($server->getAddress()); - Block\sleep(0.1, null); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.1)); } public function testDoesEmitConnectionForNewConnectionToResumedServer() @@ -158,7 +157,7 @@ public function testDoesEmitConnectionForNewConnectionToResumedServer() $server->resume(); - Block\await($peer, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); } @@ -195,7 +194,7 @@ public function testEmitsConnectionWithInheritedContextOptions() $client = stream_socket_client($server->getAddress()); - $all = Block\await($peer, null, self::TIMEOUT); + $all = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertEquals(array('socket' => array('backlog' => 4)), $all); @@ -217,7 +216,7 @@ public function testDoesNotEmitSecureConnectionForNewPlaintextConnectionThatIsId $client = stream_socket_client(str_replace('tls://', '', $server->getAddress())); - Block\sleep(0.1, null); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.1)); $server->close(); } diff --git a/tests/SocketServerTest.php b/tests/SocketServerTest.php index 0011fbaa..8afbff4b 100644 --- a/tests/SocketServerTest.php +++ b/tests/SocketServerTest.php @@ -2,7 +2,6 @@ namespace React\Tests\Socket; -use Clue\React\Block; use React\Promise\Promise; use React\Socket\ConnectionInterface; use React\Socket\SocketServer; @@ -74,7 +73,7 @@ public function testConstructorCreatesExpectedTcpServer() $promise = $connector->connect($socket->getAddress()); $promise->then($this->expectCallableOnce(), $this->expectCallableNever()); - $connection = Block\await($connector->connect($socket->getAddress()), null, self::TIMEOUT); + $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect($socket->getAddress()), self::TIMEOUT)); $socket->close(); $promise->then(function (ConnectionInterface $connection) { @@ -97,7 +96,7 @@ public function testConstructorCreatesExpectedUnixServer() $connector->connect($socket->getAddress()) ->then($this->expectCallableOnce(), $this->expectCallableNever()); - $connection = Block\await($connector->connect($socket->getAddress()), null, self::TIMEOUT); + $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect($socket->getAddress()), self::TIMEOUT)); $socket->close(); } @@ -163,7 +162,7 @@ public function testEmitsConnectionForNewConnection() $client = stream_socket_client($socket->getAddress()); - Block\await($peer, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $socket->close(); } @@ -176,7 +175,7 @@ public function testDoesNotEmitConnectionForNewConnectionToPausedServer() $client = stream_socket_client($socket->getAddress()); - Block\sleep(0.1); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.1)); } public function testDoesEmitConnectionForNewConnectionToResumedServer() @@ -193,7 +192,7 @@ public function testDoesEmitConnectionForNewConnectionToResumedServer() $socket->resume(); - Block\await($peer, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $socket->close(); } @@ -232,7 +231,7 @@ public function testEmitsConnectionWithInheritedContextOptions() $client = stream_socket_client($socket->getAddress()); - $all = Block\await($peer, null, self::TIMEOUT); + $all = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertEquals(array('socket' => array('backlog' => 4)), $all); @@ -254,7 +253,7 @@ public function testDoesNotEmitSecureConnectionForNewPlaintextConnectionThatIsId $client = stream_socket_client(str_replace('tls://', '', $socket->getAddress())); - Block\sleep(0.1); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.1)); $socket->close(); } diff --git a/tests/TcpConnectorTest.php b/tests/TcpConnectorTest.php index 9fc2fd4b..e69b8420 100644 --- a/tests/TcpConnectorTest.php +++ b/tests/TcpConnectorTest.php @@ -2,7 +2,6 @@ namespace React\Tests\Socket; -use Clue\React\Block; use React\EventLoop\Loop; use React\Socket\ConnectionInterface; use React\Socket\TcpConnector; @@ -42,7 +41,7 @@ public function connectionToEmptyPortShouldFailWithoutCallingCustomErrorHandler( ); try { - Block\await($promise, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); restore_error_handler(); } catch (\Exception $e) { @@ -78,7 +77,7 @@ public function connectionToTcpServerShouldSucceed() $connector = new TcpConnector(); - $connection = Block\await($connector->connect('127.0.0.1:9999'), null, self::TIMEOUT); + $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $connection); @@ -130,7 +129,7 @@ class_exists('PHPUnit\Framework\Error\Warning', true); } $this->setExpectedException('RuntimeException'); - Block\await($connector->connect('127.0.0.1:9999'), null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); } /** @test */ @@ -162,7 +161,7 @@ public function connectionToInvalidNetworkShouldFailWithUnreachableError() 'Connection to ' . $address . ' failed: ' . (function_exists('socket_strerror') ? socket_strerror($enetunreach) . ' (ENETUNREACH)' : 'Network is unreachable'), $enetunreach ); - Block\await($promise, null, self::TIMEOUT); + \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } /** @test */ @@ -172,7 +171,7 @@ public function connectionToTcpServerShouldSucceedWithRemoteAdressSameAsTarget() $connector = new TcpConnector(); - $connection = Block\await($connector->connect('127.0.0.1:9999'), null, self::TIMEOUT); + $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); /* @var $connection ConnectionInterface */ $this->assertEquals('tcp://127.0.0.1:9999', $connection->getRemoteAddress()); @@ -188,7 +187,7 @@ public function connectionToTcpServerShouldSucceedWithLocalAdressOnLocalhost() $connector = new TcpConnector(); - $connection = Block\await($connector->connect('127.0.0.1:9999'), null, self::TIMEOUT); + $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); /* @var $connection ConnectionInterface */ $this->assertContainsString('tcp://127.0.0.1:', $connection->getLocalAddress()); @@ -205,7 +204,7 @@ public function connectionToTcpServerShouldSucceedWithNullAddressesAfterConnecti $connector = new TcpConnector(); - $connection = Block\await($connector->connect('127.0.0.1:9999'), null, self::TIMEOUT); + $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); /* @var $connection ConnectionInterface */ $server->close(); @@ -259,7 +258,7 @@ public function connectionToIp6TcpServerShouldSucceed() $connector = new TcpConnector(); - $connection = Block\await($connector->connect('[::1]:9999'), null, self::TIMEOUT); + $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('[::1]:9999'), self::TIMEOUT)); /* @var $connection ConnectionInterface */ $this->assertEquals('tcp://[::1]:9999', $connection->getRemoteAddress()); @@ -358,7 +357,7 @@ public function cancellingConnectionShouldRejectPromise() ); try { - Block\await($promise); + \Clue\React\Block\await($promise); } catch (\Exception $e) { $server->close(); throw $e; diff --git a/tests/TcpServerTest.php b/tests/TcpServerTest.php index 309874e8..638fae1d 100644 --- a/tests/TcpServerTest.php +++ b/tests/TcpServerTest.php @@ -2,7 +2,6 @@ namespace React\Tests\Socket; -use Clue\React\Block; use React\EventLoop\Loop; use React\Socket\TcpServer; use React\Stream\DuplexResourceStream; @@ -53,7 +52,7 @@ public function testServerEmitsConnectionEventForNewConnection() $server->on('connection', $resolve); }); - $connection = Block\await($promise, null, self::TIMEOUT); + $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $connection); } @@ -374,6 +373,6 @@ private function tick() $this->markTestSkipped('Not supported on Windows'); } - Block\sleep(0); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.0)); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index daf4e4aa..755c8794 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,10 +2,9 @@ namespace React\Tests\Socket; -use React\Stream\ReadableStreamInterface; -use Clue\React\Block; -use React\Promise\Promise; use PHPUnit\Framework\TestCase as BaseTestCase; +use React\Promise\Promise; +use React\Stream\ReadableStreamInterface; class TestCase extends BaseTestCase { @@ -76,7 +75,7 @@ protected function buffer(ReadableStreamInterface $stream, $timeout) return ''; } - return Block\await(new Promise( + return \Clue\React\Block\await(\React\Promise\Timer\timeout(new Promise( function ($resolve, $reject) use ($stream) { $buffer = ''; $stream->on('data', function ($chunk) use (&$buffer) { @@ -93,7 +92,7 @@ function () use ($stream) { $stream->close(); throw new \RuntimeException(); } - ), null, $timeout); + ), $timeout)); } public function setExpectedException($exception, $exceptionMessage = '', $exceptionCode = null) diff --git a/tests/TimeoutConnectorTest.php b/tests/TimeoutConnectorTest.php index 806b16c5..c758aa4c 100644 --- a/tests/TimeoutConnectorTest.php +++ b/tests/TimeoutConnectorTest.php @@ -2,11 +2,10 @@ namespace React\Tests\Socket; -use Clue\React\Block; -use React\Socket\TimeoutConnector; -use React\Promise; use React\EventLoop\Loop; +use React\Promise; use React\Promise\Deferred; +use React\Socket\TimeoutConnector; class TimeoutConnectorTest extends TestCase { @@ -37,7 +36,7 @@ public function testRejectsWithTimeoutReasonOnTimeout() 'Connection to google.com:80 timed out after 0.01 seconds (ETIMEDOUT)', \defined('SOCKET_ETIMEDOUT') ? \SOCKET_ETIMEDOUT : 110 ); - Block\await($timeout->connect('google.com:80')); + \Clue\React\Block\await($timeout->connect('google.com:80')); } public function testRejectsWithOriginalReasonWhenConnectorRejects() @@ -54,7 +53,7 @@ public function testRejectsWithOriginalReasonWhenConnectorRejects() 'Failed', 42 ); - Block\await($timeout->connect('google.com:80')); + \Clue\React\Block\await($timeout->connect('google.com:80')); } public function testResolvesWhenConnectorResolves() diff --git a/tests/TimerSpeedUpEventLoop.php b/tests/TimerSpeedUpEventLoop.php index 97308023..485fd38e 100644 --- a/tests/TimerSpeedUpEventLoop.php +++ b/tests/TimerSpeedUpEventLoop.php @@ -2,12 +2,8 @@ namespace React\Tests\Socket; -use React\Dns\Model\Message; -use React\Dns\Resolver\ResolverInterface; use React\EventLoop\LoopInterface; use React\EventLoop\TimerInterface; -use React\Promise; -use React\Promise\CancellablePromiseInterface; /** * @internal diff --git a/tests/UnixServerTest.php b/tests/UnixServerTest.php index 711ee988..90a1b989 100644 --- a/tests/UnixServerTest.php +++ b/tests/UnixServerTest.php @@ -2,7 +2,6 @@ namespace React\Tests\Socket; -use Clue\React\Block; use React\EventLoop\Loop; use React\Socket\UnixServer; use React\Stream\DuplexResourceStream; @@ -383,6 +382,6 @@ private function getRandomSocketUri() private function tick() { - Block\sleep(0); + \Clue\React\Block\await(\React\Promise\Timer\sleep(0.0)); } } From b456e9b00dc3aee9f9972d18c38c4ac654a2ac33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Thu, 4 Aug 2022 11:58:52 +0200 Subject: [PATCH 2/2] Update to use new reactphp/async package instead of clue/reactphp-block --- composer.json | 2 +- tests/FdServerTest.php | 2 +- tests/FunctionalConnectorTest.php | 16 ++++----- tests/FunctionalSecureServerTest.php | 52 ++++++++++++++-------------- tests/FunctionalTcpServerTest.php | 37 +++++++++++++------- tests/IntegrationTest.php | 44 +++++++++++------------ tests/LimitingServerTest.php | 6 ++-- tests/SecureIntegrationTest.php | 22 ++++++------ tests/ServerTest.php | 14 ++++---- tests/SocketServerTest.php | 14 ++++---- tests/TcpConnectorTest.php | 18 +++++----- tests/TcpServerTest.php | 5 +-- tests/TestCase.php | 2 +- tests/TimeoutConnectorTest.php | 7 ++-- tests/UnixServerTest.php | 2 +- 15 files changed, 129 insertions(+), 114 deletions(-) diff --git a/composer.json b/composer.json index ec50942e..ede57084 100644 --- a/composer.json +++ b/composer.json @@ -35,8 +35,8 @@ "react/stream": "^1.2" }, "require-dev": { - "clue/block-react": "^1.5", "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35", + "react/async": "^4 || ^3 || ^2", "react/promise-stream": "^1.2" }, "autoload": { diff --git a/tests/FdServerTest.php b/tests/FdServerTest.php index 21c38c1b..e464a1b6 100644 --- a/tests/FdServerTest.php +++ b/tests/FdServerTest.php @@ -321,7 +321,7 @@ public function testServerEmitsConnectionEventForNewConnection() $server->on('connection', $resolve); }); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, 1.0)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($promise, 1.0)); /** * @var ConnectionInterface $connection diff --git a/tests/FunctionalConnectorTest.php b/tests/FunctionalConnectorTest.php index b0c4bb5f..0d003f40 100644 --- a/tests/FunctionalConnectorTest.php +++ b/tests/FunctionalConnectorTest.php @@ -23,7 +23,7 @@ public function connectionToTcpServerShouldSucceedWithLocalhost() $connector = new Connector(array()); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('localhost:9998'), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('localhost:9998'), self::TIMEOUT)); $server->close(); @@ -62,11 +62,11 @@ public function testConnectTwiceWithoutHappyEyeBallsOnlySendsSingleDnsQueryDueTo fclose($client); }); - $connection = \Clue\React\Block\await($connector->connect('example.com:80')); + $connection = \React\Async\await($connector->connect('example.com:80')); $connection->close(); $this->assertEquals(1, $received); - $connection = \Clue\React\Block\await($connector->connect('example.com:80')); + $connection = \React\Async\await($connector->connect('example.com:80')); $connection->close(); $this->assertEquals(1, $received); @@ -84,7 +84,7 @@ public function connectionToRemoteTCP4n6ServerShouldResultInOurIP() $connector = new Connector(array('happy_eyeballs' => true)); - $ip = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->request('dual.tlund.se', $connector), self::TIMEOUT)); + $ip = \React\Async\await(\React\Promise\Timer\timeout($this->request('dual.tlund.se', $connector), self::TIMEOUT)); $this->assertNotFalse(inet_pton($ip)); } @@ -98,7 +98,7 @@ public function connectionToRemoteTCP4ServerShouldResultInOurIP() $connector = new Connector(array('happy_eyeballs' => true)); try { - $ip = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->request('ipv4.tlund.se', $connector), self::TIMEOUT)); + $ip = \React\Async\await(\React\Promise\Timer\timeout($this->request('ipv4.tlund.se', $connector), self::TIMEOUT)); } catch (\Exception $e) { $this->checkIpv4(); throw $e; @@ -117,7 +117,7 @@ public function connectionToRemoteTCP6ServerShouldResultInOurIP() $connector = new Connector(array('happy_eyeballs' => true)); try { - $ip = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->request('ipv6.tlund.se', $connector), self::TIMEOUT)); + $ip = \React\Async\await(\React\Promise\Timer\timeout($this->request('ipv6.tlund.se', $connector), self::TIMEOUT)); } catch (\Exception $e) { $this->checkIpv6(); throw $e; @@ -150,11 +150,11 @@ public function testCancelPendingTlsConnectionDuringTlsHandshakeShouldCloseTcpCo }); }); - \Clue\React\Block\await(\React\Promise\Timer\timeout($deferred->promise(), self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($deferred->promise(), self::TIMEOUT)); $server->close(); try { - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->fail(); } catch (\Exception $e) { $this->assertInstanceOf('RuntimeException', $e); diff --git a/tests/FunctionalSecureServerTest.php b/tests/FunctionalSecureServerTest.php index 071daf29..e3a8fca6 100644 --- a/tests/FunctionalSecureServerTest.php +++ b/tests/FunctionalSecureServerTest.php @@ -37,7 +37,7 @@ public function testClientCanConnectToServer() $promise = $connector->connect($server->getAddress()); /* @var ConnectionInterface $client */ - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $client); $this->assertEquals($server->getAddress(), $client->getRemoteAddress()); @@ -66,7 +66,7 @@ public function testClientUsesTls13ByDefaultWhenSupportedByOpenSSL() $promise = $connector->connect($server->getAddress()); /* @var ConnectionInterface $client */ - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\Connection', $client); $this->assertTrue(isset($client->stream)); @@ -105,7 +105,7 @@ public function testClientUsesTls12WhenCryptoMethodIsExplicitlyConfiguredByClien $promise = $connector->connect($server->getAddress()); /* @var ConnectionInterface $client */ - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\Connection', $client); $this->assertTrue(isset($client->stream)); @@ -136,7 +136,7 @@ public function testClientUsesTls12WhenCryptoMethodIsExplicitlyConfiguredByServe $promise = $connector->connect($server->getAddress()); /* @var ConnectionInterface $client */ - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\Connection', $client); $this->assertTrue(isset($client->stream)); @@ -168,7 +168,7 @@ public function testClientUsesTls10WhenCryptoMethodIsExplicitlyConfiguredByClien /* @var ConnectionInterface $client */ try { - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\RuntimeException $e) { // legacy TLS 1.0 would be considered insecure by today's standards, so skip test if connection fails // OpenSSL error messages are version/platform specific @@ -210,7 +210,7 @@ public function testServerEmitsConnectionForClientConnection() // await both client and server side end of connection /* @var ConnectionInterface[] $both */ - $both = \Clue\React\Block\await(\React\Promise\Timer\timeout(\React\Promise\all(array($peer, $client)), self::TIMEOUT)); + $both = \React\Async\await(\React\Promise\Timer\timeout(\React\Promise\all(array($peer, $client)), self::TIMEOUT)); // both ends of the connection are represented by different instances of ConnectionInterface $this->assertCount(2, $both); @@ -250,7 +250,7 @@ public function testClientEmitsDataEventOnceForDataWrittenFromServer() }, $reject); }); - $data = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $data = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals('foo', $data); @@ -291,7 +291,7 @@ public function testWritesDataInMultipleChunksToConnection() }, $reject); }); - $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(400000, $received); @@ -332,7 +332,7 @@ public function testWritesMoreDataInMultipleChunksToConnection() }, $reject); }); - $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(2000000, $received); @@ -365,7 +365,7 @@ public function testEmitsDataFromConnection() $connection->write('foo'); }); - $data = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $data = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals('foo', $data); @@ -405,7 +405,7 @@ public function testEmitsDataInMultipleChunksFromConnection() $connection->write(str_repeat('*', 400000)); }); - $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(400000, $received); @@ -447,7 +447,7 @@ public function testPipesDataBackInMultipleChunksFromConnection() }, $reject); }); - $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(400000, $received); @@ -477,7 +477,7 @@ public function testEmitsConnectionForNewTlsv11Connection() )); $promise = $connector->connect($server->getAddress()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $server->close(); $promise->then(function (ConnectionInterface $connection) { @@ -508,7 +508,7 @@ public function testEmitsErrorForClientWithTlsVersionMismatch() $this->setExpectedException('RuntimeException', 'handshake'); try { - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -534,7 +534,7 @@ public function testServerEmitsConnectionForNewConnectionWithEncryptedCertificat )); $connector->connect($server->getAddress()); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $connection); @@ -557,7 +557,7 @@ public function testClientRejectsWithErrorForServerWithInvalidCertificate() $this->setExpectedException('RuntimeException', 'handshake'); try { - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -587,7 +587,7 @@ public function testServerEmitsErrorForClientWithInvalidCertificate() $this->setExpectedException('RuntimeException', 'handshake'); try { - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -616,7 +616,7 @@ public function testEmitsErrorForServerWithEncryptedCertificateMissingPassphrase $this->setExpectedException('RuntimeException', 'handshake'); try { - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -646,7 +646,7 @@ public function testEmitsErrorForServerWithEncryptedCertificateWithInvalidPassph $this->setExpectedException('RuntimeException', 'handshake'); try { - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } catch (\Exception $e) { $server->close(); @@ -669,7 +669,7 @@ public function testEmitsErrorForConnectionWithPeerVerification() $promise = $connector->connect($server->getAddress()); $promise->then(null, $this->expectCallableOnce()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); $server->close(); } @@ -694,7 +694,7 @@ public function testEmitsErrorIfConnectionIsCancelled() $promise->cancel(); $promise->then(null, $this->expectCallableOnce()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); $server->close(); } @@ -715,7 +715,7 @@ public function testEmitsErrorIfConnectionIsClosedBeforeHandshake() $stream->close(); }); - $error = \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); + $error = \React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); // Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshake (ECONNRESET) $this->assertInstanceOf('RuntimeException', $error); @@ -743,7 +743,7 @@ public function testEmitsErrorIfConnectionIsClosedWithIncompleteHandshake() $stream->end("\x1e"); }); - $error = \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); + $error = \React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); // Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshake (ECONNRESET) $this->assertInstanceOf('RuntimeException', $error); @@ -767,7 +767,7 @@ public function testEmitsNothingIfPlaintextConnectionIsIdle() $connector = new TcpConnector(); $promise = $connector->connect(str_replace('tls://', '', $server->getAddress())); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $connection); $server->close(); @@ -792,7 +792,7 @@ public function testEmitsErrorIfConnectionIsHttpInsteadOfSecureHandshake() $stream->write("GET / HTTP/1.0\r\n\r\n"); }); - $error = \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); + $error = \React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); $this->assertInstanceOf('RuntimeException', $error); @@ -821,7 +821,7 @@ public function testEmitsErrorIfConnectionIsUnknownProtocolInsteadOfSecureHandsh $stream->write("Hello world!\n"); }); - $error = \Clue\React\Block\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); + $error = \React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT)); $this->assertInstanceOf('RuntimeException', $error); diff --git a/tests/FunctionalTcpServerTest.php b/tests/FunctionalTcpServerTest.php index b3260da5..76026ad7 100644 --- a/tests/FunctionalTcpServerTest.php +++ b/tests/FunctionalTcpServerTest.php @@ -25,7 +25,8 @@ public function testEmitsConnectionForNewConnection() $promise->then($this->expectCallableOnce()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $server->close(); @@ -45,7 +46,8 @@ public function testEmitsNoConnectionForNewConnectionWhenPaused() $promise->then($this->expectCallableOnce()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); } public function testConnectionForNewConnectionWhenResumedAfterPause() @@ -64,7 +66,8 @@ public function testConnectionForNewConnectionWhenResumedAfterPause() $promise->then($this->expectCallableOnce()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $server->close(); $promise->then(function (ConnectionInterface $connection) { @@ -86,7 +89,8 @@ public function testEmitsConnectionWithRemoteIp() $promise->then($this->expectCallableOnce()); - $peer = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $peer = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $this->assertContainsString('127.0.0.1:', $peer); @@ -112,7 +116,8 @@ public function testEmitsConnectionWithLocalIp() $promise->then($this->expectCallableOnce()); - $local = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $local = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $this->assertContainsString('127.0.0.1:', $local); $this->assertEquals($server->getAddress(), $local); @@ -141,7 +146,8 @@ public function testEmitsConnectionWithLocalIpDespiteListeningOnAll() $promise->then($this->expectCallableOnce()); - $local = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $local = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $this->assertContainsString('127.0.0.1:', $local); @@ -167,7 +173,7 @@ public function testEmitsConnectionWithRemoteIpAfterConnectionIsClosedByPeer() $connection->end(); }); - $peer = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $peer = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertContainsString('127.0.0.1:', $peer); @@ -189,7 +195,8 @@ public function testEmitsConnectionWithRemoteNullAddressAfterConnectionIsClosedB $promise->then($this->expectCallableOnce()); - $peer = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $peer = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $this->assertNull($peer); @@ -215,7 +222,7 @@ public function testEmitsConnectionEvenIfClientConnectionIsCancelled() $promise->then(null, $this->expectCallableOnce()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); } @@ -239,7 +246,8 @@ public function testEmitsConnectionForNewIpv6Connection() $promise->then($this->expectCallableOnce()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $server->close(); $promise->then(function (ConnectionInterface $connection) { @@ -266,7 +274,8 @@ public function testEmitsConnectionWithRemoteIpv6() $promise->then($this->expectCallableOnce()); - $peer = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $peer = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $this->assertContainsString('[::1]:', $peer); @@ -295,7 +304,8 @@ public function testEmitsConnectionWithLocalIpv6() $promise->then($this->expectCallableOnce()); - $local = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $local = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $this->assertContainsString('[::1]:', $local); $this->assertEquals($server->getAddress(), $local); @@ -360,7 +370,8 @@ public function testEmitsConnectionWithInheritedContextOptions() $promise->then($this->expectCallableOnce()); - $all = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $all = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); $this->assertEquals(array('socket' => array('backlog' => 4)), $all); diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 9e4c1c77..dfd15ce5 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -18,7 +18,7 @@ public function gettingStuffFromGoogleShouldWork() { $connector = new Connector(array()); - $conn = \Clue\React\Block\await($connector->connect('google.com:80')); + $conn = \React\Async\await($connector->connect('google.com:80')); $this->assertContainsString(':80', $conn->getRemoteAddress()); $this->assertNotEquals('google.com:80', $conn->getRemoteAddress()); @@ -39,7 +39,7 @@ public function gettingEncryptedStuffFromGoogleShouldWork() $secureConnector = new Connector(array()); - $conn = \Clue\React\Block\await($secureConnector->connect('tls://google.com:443')); + $conn = \React\Async\await($secureConnector->connect('tls://google.com:443')); $conn->write("GET / HTTP/1.0\r\n\r\n"); @@ -65,7 +65,7 @@ public function gettingEncryptedStuffFromGoogleShouldWorkIfHostIsResolvedFirst() $dns ); - $conn = \Clue\React\Block\await($connector->connect('google.com:443')); + $conn = \React\Async\await($connector->connect('google.com:443')); $conn->write("GET / HTTP/1.0\r\n\r\n"); @@ -79,7 +79,7 @@ public function gettingPlaintextStuffFromEncryptedGoogleShouldNotWork() { $connector = new Connector(array()); - $conn = \Clue\React\Block\await($connector->connect('google.com:443')); + $conn = \React\Async\await($connector->connect('google.com:443')); $this->assertContainsString(':443', $conn->getRemoteAddress()); $this->assertNotEquals('google.com:443', $conn->getRemoteAddress()); @@ -105,7 +105,7 @@ public function testConnectingFailsIfConnectorUsesInvalidDnsResolverAddress() )); $this->setExpectedException('RuntimeException'); - \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('google.com:80'), self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($connector->connect('google.com:80'), self::TIMEOUT)); } public function testCancellingPendingConnectionWithoutTimeoutShouldNotCreateAnyGarbageReferences() @@ -162,11 +162,11 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect connection refused error - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); + \React\Async\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.2)); + \React\Async\await(\React\Promise\Timer\sleep(0.2)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(2.0)); + \React\Async\await(\React\Promise\Timer\sleep(2.0)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -197,9 +197,9 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect a connection timeout error - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); + \React\Async\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.2)); + \React\Async\await(\React\Promise\Timer\sleep(0.2)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -229,9 +229,9 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect a connection timeout error - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); + \React\Async\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.2)); + \React\Async\await(\React\Promise\Timer\sleep(0.2)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -261,11 +261,11 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect a DNS error - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); + \React\Async\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.2)); + \React\Async\await(\React\Promise\Timer\sleep(0.2)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(2.0)); + \React\Async\await(\React\Promise\Timer\sleep(2.0)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -303,11 +303,11 @@ function ($e) use (&$wait) { ); // run loop for short period to ensure we detect a TLS error - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.01)); + \React\Async\await(\React\Promise\Timer\sleep(0.01)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.4)); + \React\Async\await(\React\Promise\Timer\sleep(0.4)); if ($wait) { - \Clue\React\Block\await(\React\Promise\Timer\sleep(self::TIMEOUT - 0.5)); + \React\Async\await(\React\Promise\Timer\sleep(self::TIMEOUT - 0.5)); if ($wait) { $this->fail('Connection attempt did not fail'); } @@ -332,7 +332,7 @@ function ($conn) { $conn->close(); } ); - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); unset($promise); $this->assertEquals(0, gc_collect_cycles()); @@ -345,7 +345,7 @@ public function testConnectingFailsIfTimeoutIsTooSmall() )); $this->setExpectedException('RuntimeException'); - \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('google.com:80'), self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($connector->connect('google.com:80'), self::TIMEOUT)); } public function testSelfSignedRejectsIfVerificationIsEnabled() @@ -361,7 +361,7 @@ public function testSelfSignedRejectsIfVerificationIsEnabled() )); $this->setExpectedException('RuntimeException'); - \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('tls://self-signed.badssl.com:443'), self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($connector->connect('tls://self-signed.badssl.com:443'), self::TIMEOUT)); } public function testSelfSignedResolvesIfVerificationIsDisabled() @@ -376,7 +376,7 @@ public function testSelfSignedResolvesIfVerificationIsDisabled() ) )); - $conn = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('tls://self-signed.badssl.com:443'), self::TIMEOUT)); + $conn = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('tls://self-signed.badssl.com:443'), self::TIMEOUT)); $conn->close(); // if we reach this, then everything is good diff --git a/tests/LimitingServerTest.php b/tests/LimitingServerTest.php index 53d3a471..1d054f73 100644 --- a/tests/LimitingServerTest.php +++ b/tests/LimitingServerTest.php @@ -156,7 +156,7 @@ public function testSocketDisconnectionWillRemoveFromList() }); }); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertEquals(array(), $server->getConnections()); @@ -177,7 +177,7 @@ public function testPausingServerWillEmitOnlyOneButAcceptTwoConnectionsDueToOper $first = stream_socket_client($server->getAddress()); $second = stream_socket_client($server->getAddress()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); fclose($first); fclose($second); @@ -207,7 +207,7 @@ public function testPausingServerWillEmitTwoConnectionsFromBacklog() $second = stream_socket_client($server->getAddress()); fclose($second); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); } diff --git a/tests/SecureIntegrationTest.php b/tests/SecureIntegrationTest.php index 8d6d1829..f3b09668 100644 --- a/tests/SecureIntegrationTest.php +++ b/tests/SecureIntegrationTest.php @@ -49,7 +49,7 @@ public function tearDownServer() public function testConnectToServer() { - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ $client->close(); @@ -64,7 +64,7 @@ public function testConnectToServerEmitsConnection() $promiseClient = $this->connector->connect($this->address); - list($_, $client) = \Clue\React\Block\await(\React\Promise\Timer\timeout(\React\Promise\all(array($promiseServer, $promiseClient)), self::TIMEOUT)); + list($_, $client) = \React\Async\await(\React\Promise\Timer\timeout(\React\Promise\all(array($promiseServer, $promiseClient)), self::TIMEOUT)); /* @var $client ConnectionInterface */ $client->close(); @@ -80,13 +80,13 @@ public function testSendSmallDataToServerReceivesOneChunk() }); }); - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ $client->write('hello'); // await server to report one "data" event - $data = \Clue\React\Block\await(\React\Promise\Timer\timeout($received->promise(), self::TIMEOUT)); + $data = \React\Async\await(\React\Promise\Timer\timeout($received->promise(), self::TIMEOUT)); $client->close(); @@ -121,14 +121,14 @@ public function testSendDataWithEndToServerReceivesAllData() }); }); - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ $data = str_repeat('a', 200000); $client->end($data); // await server to report connection "close" event - $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($disconnected->promise(), self::TIMEOUT)); + $received = \React\Async\await(\React\Promise\Timer\timeout($disconnected->promise(), self::TIMEOUT)); $this->assertEquals(strlen($data), strlen($received)); $this->assertEquals($data, $received); @@ -156,7 +156,7 @@ public function testSendDataWithoutEndingToServerReceivesAllData() $connection->write($data); }); - $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(strlen($data), strlen($received)); $this->assertEquals($data, $received); @@ -172,12 +172,12 @@ public function testConnectToServerWhichSendsSmallDataReceivesOneChunk() $peer->write('hello'); }); - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ // await client to report one "data" event $receive = $this->createPromiseForEvent($client, 'data', $this->expectCallableOnceWith('hello')); - \Clue\React\Block\await(\React\Promise\Timer\timeout($receive, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($receive, self::TIMEOUT)); $client->close(); } @@ -189,7 +189,7 @@ public function testConnectToServerWhichSendsDataWithEndReceivesAllData() $peer->end($data); }); - $client = \Clue\React\Block\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); + $client = \React\Async\await(\React\Promise\Timer\timeout($this->connector->connect($this->address), self::TIMEOUT)); /* @var $client ConnectionInterface */ // await data from client until it closes @@ -220,7 +220,7 @@ public function testConnectToServerWhichSendsDataWithoutEndingReceivesAllData() }, $reject); }); - $received = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertEquals(strlen($data), $received); diff --git a/tests/ServerTest.php b/tests/ServerTest.php index 0005ab0f..fa1c894e 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -52,7 +52,7 @@ public function testConstructorCreatesExpectedTcpServer() $promise = $connector->connect($server->getAddress()); $promise->then($this->expectCallableOnce(), $this->expectCallableNever()); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect($server->getAddress()), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect($server->getAddress()), self::TIMEOUT)); $server->close(); $promise->then(function (ConnectionInterface $connection) { @@ -75,7 +75,7 @@ public function testConstructorCreatesExpectedUnixServer() $connector->connect($server->getAddress()) ->then($this->expectCallableOnce(), $this->expectCallableNever()); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect($server->getAddress()), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect($server->getAddress()), self::TIMEOUT)); $connection->close(); $server->close(); @@ -127,7 +127,7 @@ public function testEmitsConnectionForNewConnection() $client = stream_socket_client($server->getAddress()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); } @@ -140,7 +140,7 @@ public function testDoesNotEmitConnectionForNewConnectionToPausedServer() $client = stream_socket_client($server->getAddress()); - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.1)); + \React\Async\await(\React\Promise\Timer\sleep(0.1)); } public function testDoesEmitConnectionForNewConnectionToResumedServer() @@ -157,7 +157,7 @@ public function testDoesEmitConnectionForNewConnectionToResumedServer() $server->resume(); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $server->close(); } @@ -194,7 +194,7 @@ public function testEmitsConnectionWithInheritedContextOptions() $client = stream_socket_client($server->getAddress()); - $all = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $all = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertEquals(array('socket' => array('backlog' => 4)), $all); @@ -216,7 +216,7 @@ public function testDoesNotEmitSecureConnectionForNewPlaintextConnectionThatIsId $client = stream_socket_client(str_replace('tls://', '', $server->getAddress())); - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.1)); + \React\Async\await(\React\Promise\Timer\sleep(0.1)); $server->close(); } diff --git a/tests/SocketServerTest.php b/tests/SocketServerTest.php index 8afbff4b..2f5d93b9 100644 --- a/tests/SocketServerTest.php +++ b/tests/SocketServerTest.php @@ -73,7 +73,7 @@ public function testConstructorCreatesExpectedTcpServer() $promise = $connector->connect($socket->getAddress()); $promise->then($this->expectCallableOnce(), $this->expectCallableNever()); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect($socket->getAddress()), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect($socket->getAddress()), self::TIMEOUT)); $socket->close(); $promise->then(function (ConnectionInterface $connection) { @@ -96,7 +96,7 @@ public function testConstructorCreatesExpectedUnixServer() $connector->connect($socket->getAddress()) ->then($this->expectCallableOnce(), $this->expectCallableNever()); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect($socket->getAddress()), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect($socket->getAddress()), self::TIMEOUT)); $socket->close(); } @@ -162,7 +162,7 @@ public function testEmitsConnectionForNewConnection() $client = stream_socket_client($socket->getAddress()); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $socket->close(); } @@ -175,7 +175,7 @@ public function testDoesNotEmitConnectionForNewConnectionToPausedServer() $client = stream_socket_client($socket->getAddress()); - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.1)); + \React\Async\await(\React\Promise\Timer\sleep(0.1)); } public function testDoesEmitConnectionForNewConnectionToResumedServer() @@ -192,7 +192,7 @@ public function testDoesEmitConnectionForNewConnectionToResumedServer() $socket->resume(); - \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $socket->close(); } @@ -231,7 +231,7 @@ public function testEmitsConnectionWithInheritedContextOptions() $client = stream_socket_client($socket->getAddress()); - $all = \Clue\React\Block\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); + $all = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT)); $this->assertEquals(array('socket' => array('backlog' => 4)), $all); @@ -253,7 +253,7 @@ public function testDoesNotEmitSecureConnectionForNewPlaintextConnectionThatIsId $client = stream_socket_client(str_replace('tls://', '', $socket->getAddress())); - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.1)); + \React\Async\await(\React\Promise\Timer\sleep(0.1)); $socket->close(); } diff --git a/tests/TcpConnectorTest.php b/tests/TcpConnectorTest.php index e69b8420..0973f726 100644 --- a/tests/TcpConnectorTest.php +++ b/tests/TcpConnectorTest.php @@ -41,7 +41,7 @@ public function connectionToEmptyPortShouldFailWithoutCallingCustomErrorHandler( ); try { - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); restore_error_handler(); } catch (\Exception $e) { @@ -77,7 +77,7 @@ public function connectionToTcpServerShouldSucceed() $connector = new TcpConnector(); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $connection); @@ -129,7 +129,7 @@ class_exists('PHPUnit\Framework\Error\Warning', true); } $this->setExpectedException('RuntimeException'); - \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); } /** @test */ @@ -161,7 +161,7 @@ public function connectionToInvalidNetworkShouldFailWithUnreachableError() 'Connection to ' . $address . ' failed: ' . (function_exists('socket_strerror') ? socket_strerror($enetunreach) . ' (ENETUNREACH)' : 'Network is unreachable'), $enetunreach ); - \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); } /** @test */ @@ -171,7 +171,7 @@ public function connectionToTcpServerShouldSucceedWithRemoteAdressSameAsTarget() $connector = new TcpConnector(); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); /* @var $connection ConnectionInterface */ $this->assertEquals('tcp://127.0.0.1:9999', $connection->getRemoteAddress()); @@ -187,7 +187,7 @@ public function connectionToTcpServerShouldSucceedWithLocalAdressOnLocalhost() $connector = new TcpConnector(); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); /* @var $connection ConnectionInterface */ $this->assertContainsString('tcp://127.0.0.1:', $connection->getLocalAddress()); @@ -204,7 +204,7 @@ public function connectionToTcpServerShouldSucceedWithNullAddressesAfterConnecti $connector = new TcpConnector(); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('127.0.0.1:9999'), self::TIMEOUT)); /* @var $connection ConnectionInterface */ $server->close(); @@ -258,7 +258,7 @@ public function connectionToIp6TcpServerShouldSucceed() $connector = new TcpConnector(); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($connector->connect('[::1]:9999'), self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('[::1]:9999'), self::TIMEOUT)); /* @var $connection ConnectionInterface */ $this->assertEquals('tcp://[::1]:9999', $connection->getRemoteAddress()); @@ -357,7 +357,7 @@ public function cancellingConnectionShouldRejectPromise() ); try { - \Clue\React\Block\await($promise); + \React\Async\await($promise); } catch (\Exception $e) { $server->close(); throw $e; diff --git a/tests/TcpServerTest.php b/tests/TcpServerTest.php index 638fae1d..8908d1c2 100644 --- a/tests/TcpServerTest.php +++ b/tests/TcpServerTest.php @@ -52,7 +52,7 @@ public function testServerEmitsConnectionEventForNewConnection() $server->on('connection', $resolve); }); - $connection = \Clue\React\Block\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); + $connection = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT)); $this->assertInstanceOf('React\Socket\ConnectionInterface', $connection); } @@ -71,6 +71,7 @@ public function testConnectionWithManyClients() $this->tick(); $this->tick(); $this->tick(); + $this->tick(); } public function testDataEventWillNotBeEmittedWhenClientSendsNoData() @@ -373,6 +374,6 @@ private function tick() $this->markTestSkipped('Not supported on Windows'); } - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.0)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 755c8794..b5725f90 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -75,7 +75,7 @@ protected function buffer(ReadableStreamInterface $stream, $timeout) return ''; } - return \Clue\React\Block\await(\React\Promise\Timer\timeout(new Promise( + return \React\Async\await(\React\Promise\Timer\timeout(new Promise( function ($resolve, $reject) use ($stream) { $buffer = ''; $stream->on('data', function ($chunk) use (&$buffer) { diff --git a/tests/TimeoutConnectorTest.php b/tests/TimeoutConnectorTest.php index c758aa4c..b9bff26c 100644 --- a/tests/TimeoutConnectorTest.php +++ b/tests/TimeoutConnectorTest.php @@ -31,12 +31,15 @@ public function testRejectsWithTimeoutReasonOnTimeout() $timeout = new TimeoutConnector($connector, 0.01); + $promise = $timeout->connect('google.com:80'); + Loop::run(); + $this->setExpectedException( 'RuntimeException', 'Connection to google.com:80 timed out after 0.01 seconds (ETIMEDOUT)', \defined('SOCKET_ETIMEDOUT') ? \SOCKET_ETIMEDOUT : 110 ); - \Clue\React\Block\await($timeout->connect('google.com:80')); + \React\Async\await($promise); } public function testRejectsWithOriginalReasonWhenConnectorRejects() @@ -53,7 +56,7 @@ public function testRejectsWithOriginalReasonWhenConnectorRejects() 'Failed', 42 ); - \Clue\React\Block\await($timeout->connect('google.com:80')); + \React\Async\await($timeout->connect('google.com:80')); } public function testResolvesWhenConnectorResolves() diff --git a/tests/UnixServerTest.php b/tests/UnixServerTest.php index 90a1b989..6a697f97 100644 --- a/tests/UnixServerTest.php +++ b/tests/UnixServerTest.php @@ -382,6 +382,6 @@ private function getRandomSocketUri() private function tick() { - \Clue\React\Block\await(\React\Promise\Timer\sleep(0.0)); + \React\Async\await(\React\Promise\Timer\sleep(0.0)); } }