Skip to content

Commit

Permalink
Use reactphp-block v1.5.0 and remove loop where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrings committed Jan 13, 2022
1 parent 82acd6c commit 4f2497b
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 306 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"react/stream": "^1.2"
},
"require-dev": {
"clue/block-react": "^1.2",
"clue/block-react": "^1.5",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
"react/promise-stream": "^1.2"
},
Expand Down
5 changes: 2 additions & 3 deletions tests/FdServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace React\Tests\Socket;

use Clue\React\Block;
use React\EventLoop\Loop;
use React\Promise\Promise;
use React\Socket\ConnectionInterface;
use React\Socket\FdServer;
Expand Down Expand Up @@ -303,12 +302,12 @@ public function testServerEmitsConnectionEventForNewConnection()

$client = stream_socket_client('tcp://' . stream_socket_get_name($socket, false));

$server = new FdServer($fd, Loop::get());
$server = new FdServer($fd);
$promise = new Promise(function ($resolve) use ($server) {
$server->on('connection', $resolve);
});

$connection = Block\await($promise, Loop::get(), 1.0);
$connection = Block\await($promise, null, 1.0);

/**
* @var ConnectionInterface $connection
Expand Down
30 changes: 10 additions & 20 deletions tests/FunctionalConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ class FunctionalConnectorTest extends TestCase
/** @test */
public function connectionToTcpServerShouldSucceedWithLocalhost()
{
$loop = Loop::get();

$server = new TcpServer(9998);

$connector = new Connector(array());

$connection = Block\await($connector->connect('localhost:9998'), $loop, self::TIMEOUT);
$connection = Block\await($connector->connect('localhost:9998'), null, self::TIMEOUT);

$server->close();

Expand Down Expand Up @@ -65,11 +63,11 @@ public function testConnectTwiceWithoutHappyEyeBallsOnlySendsSingleDnsQueryDueTo
fclose($client);
});

$connection = Block\await($connector->connect('example.com:80'), Loop::get());
$connection = Block\await($connector->connect('example.com:80'));
$connection->close();
$this->assertEquals(1, $received);

$connection = Block\await($connector->connect('example.com:80'), Loop::get());
$connection = Block\await($connector->connect('example.com:80'));
$connection->close();
$this->assertEquals(1, $received);

Expand All @@ -85,11 +83,9 @@ public function connectionToRemoteTCP4n6ServerShouldResultInOurIP()
// max_nesting_level was set to 100 for PHP Versions < 5.4 which resulted in failing test for legacy PHP
ini_set('xdebug.max_nesting_level', 256);

$loop = Loop::get();

$connector = new Connector(array('happy_eyeballs' => true));

$ip = Block\await($this->request('dual.tlund.se', $connector), $loop, self::TIMEOUT);
$ip = Block\await($this->request('dual.tlund.se', $connector), null, self::TIMEOUT);

$this->assertNotFalse(inet_pton($ip));
}
Expand All @@ -100,12 +96,10 @@ public function connectionToRemoteTCP4n6ServerShouldResultInOurIP()
*/
public function connectionToRemoteTCP4ServerShouldResultInOurIP()
{
$loop = Loop::get();

$connector = new Connector(array('happy_eyeballs' => true));

try {
$ip = Block\await($this->request('ipv4.tlund.se', $connector), $loop, self::TIMEOUT);
$ip = Block\await($this->request('ipv4.tlund.se', $connector), null, self::TIMEOUT);
} catch (\Exception $e) {
$this->checkIpv4();
throw $e;
Expand All @@ -121,12 +115,10 @@ public function connectionToRemoteTCP4ServerShouldResultInOurIP()
*/
public function connectionToRemoteTCP6ServerShouldResultInOurIP()
{
$loop = Loop::get();

$connector = new Connector(array('happy_eyeballs' => true));

try {
$ip = Block\await($this->request('ipv6.tlund.se', $connector), $loop, self::TIMEOUT);
$ip = Block\await($this->request('ipv6.tlund.se', $connector), null, self::TIMEOUT);
} catch (\Exception $e) {
$this->checkIpv6();
throw $e;
Expand All @@ -142,30 +134,28 @@ public function testCancelPendingTlsConnectionDuringTlsHandshakeShouldCloseTcpCo
$this->markTestSkipped('Not supported on legacy HHVM');
}

$loop = Loop::get();

$server = new TcpServer(0);
$uri = str_replace('tcp://', 'tls://', $server->getAddress());

$connector = new Connector(array());
$promise = $connector->connect($uri);

$deferred = new Deferred();
$server->on('connection', function (ConnectionInterface $connection) use ($promise, $deferred, $loop) {
$server->on('connection', function (ConnectionInterface $connection) use ($promise, $deferred) {
$connection->on('close', function () use ($deferred) {
$deferred->resolve();
});

$loop->futureTick(function () use ($promise) {
Loop::futureTick(function () use ($promise) {
$promise->cancel();
});
});

Block\await($deferred->promise(), $loop, self::TIMEOUT);
Block\await($deferred->promise(), null, self::TIMEOUT);
$server->close();

try {
Block\await($promise, $loop, self::TIMEOUT);
Block\await($promise, null, self::TIMEOUT);
$this->fail();
} catch (\Exception $e) {
$this->assertInstanceOf('RuntimeException', $e);
Expand Down
Loading

0 comments on commit 4f2497b

Please sign in to comment.