Skip to content

Commit

Permalink
Update to use new reactphp/async package instead of clue/reactphp-block
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Aug 8, 2022
1 parent 8de2763 commit b456e9b
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 114 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion tests/FdServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions tests/FunctionalConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);

Expand All @@ -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));
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
52 changes: 26 additions & 26 deletions tests/FunctionalSecureServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();

Expand All @@ -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);

Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
Loading

0 comments on commit b456e9b

Please sign in to comment.