Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test suite to use new reactphp/async package instead of clue/reactphp-block #296

Merged
merged 2 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 1 addition & 2 deletions tests/FdServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace React\Tests\Socket;

use Clue\React\Block;
use React\Promise\Promise;
use React\Socket\ConnectionInterface;
use React\Socket\FdServer;
Expand Down Expand Up @@ -322,7 +321,7 @@ public function testServerEmitsConnectionEventForNewConnection()
$server->on('connection', $resolve);
});

$connection = Block\await($promise, null, 1.0);
$connection = \React\Async\await(\React\Promise\Timer\timeout($promise, 1.0));

/**
* @var ConnectionInterface $connection
Expand Down
1 change: 0 additions & 1 deletion tests/FixedUriConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace React\Tests\Socket;

use React\Socket\FixedUriConnector;
use React\Tests\Socket\TestCase;

class FixedUriConnectorTest extends TestCase
{
Expand Down
17 changes: 8 additions & 9 deletions tests/FunctionalConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace React\Tests\Socket;

use Clue\React\Block;
use React\EventLoop\Loop;
use React\Promise\Deferred;
use React\Socket\ConnectionInterface;
Expand All @@ -24,7 +23,7 @@ public function connectionToTcpServerShouldSucceedWithLocalhost()

$connector = new Connector(array());

$connection = Block\await($connector->connect('localhost:9998'), null, self::TIMEOUT);
$connection = \React\Async\await(\React\Promise\Timer\timeout($connector->connect('localhost:9998'), self::TIMEOUT));

$server->close();

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

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

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

Expand All @@ -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 = \React\Async\await(\React\Promise\Timer\timeout($this->request('dual.tlund.se', $connector), self::TIMEOUT));

$this->assertNotFalse(inet_pton($ip));
}
Expand All @@ -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 = \React\Async\await(\React\Promise\Timer\timeout($this->request('ipv4.tlund.se', $connector), self::TIMEOUT));
} catch (\Exception $e) {
$this->checkIpv4();
throw $e;
Expand All @@ -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 = \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 @@ -151,11 +150,11 @@ public function testCancelPendingTlsConnectionDuringTlsHandshakeShouldCloseTcpCo
});
});

Block\await($deferred->promise(), null, self::TIMEOUT);
\React\Async\await(\React\Promise\Timer\timeout($deferred->promise(), self::TIMEOUT));
$server->close();

try {
Block\await($promise, null, self::TIMEOUT);
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
$this->fail();
} catch (\Exception $e) {
$this->assertInstanceOf('RuntimeException', $e);
Expand Down
54 changes: 26 additions & 28 deletions tests/FunctionalSecureServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -39,7 +37,7 @@ public function testClientCanConnectToServer()
$promise = $connector->connect($server->getAddress());

/* @var ConnectionInterface $client */
$client = Block\await($promise, null, 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 @@ -68,7 +66,7 @@ public function testClientUsesTls13ByDefaultWhenSupportedByOpenSSL()
$promise = $connector->connect($server->getAddress());

/* @var ConnectionInterface $client */
$client = Block\await($promise, null, 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 @@ -107,7 +105,7 @@ public function testClientUsesTls12WhenCryptoMethodIsExplicitlyConfiguredByClien
$promise = $connector->connect($server->getAddress());

/* @var ConnectionInterface $client */
$client = Block\await($promise, null, 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 @@ -138,7 +136,7 @@ public function testClientUsesTls12WhenCryptoMethodIsExplicitlyConfiguredByServe
$promise = $connector->connect($server->getAddress());

/* @var ConnectionInterface $client */
$client = Block\await($promise, null, 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 @@ -170,7 +168,7 @@ public function testClientUsesTls10WhenCryptoMethodIsExplicitlyConfiguredByClien

/* @var ConnectionInterface $client */
try {
$client = Block\await($promise, null, 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 @@ -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 = \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 @@ -252,7 +250,7 @@ public function testClientEmitsDataEventOnceForDataWrittenFromServer()
}, $reject);
});

$data = Block\await($promise, null, self::TIMEOUT);
$data = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));

$this->assertEquals('foo', $data);

Expand Down Expand Up @@ -293,7 +291,7 @@ public function testWritesDataInMultipleChunksToConnection()
}, $reject);
});

$received = Block\await($promise, null, self::TIMEOUT);
$received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));

$this->assertEquals(400000, $received);

Expand Down Expand Up @@ -334,7 +332,7 @@ public function testWritesMoreDataInMultipleChunksToConnection()
}, $reject);
});

$received = Block\await($promise, null, self::TIMEOUT);
$received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));

$this->assertEquals(2000000, $received);

Expand Down Expand Up @@ -367,7 +365,7 @@ public function testEmitsDataFromConnection()
$connection->write('foo');
});

$data = Block\await($promise, null, self::TIMEOUT);
$data = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));

$this->assertEquals('foo', $data);

Expand Down Expand Up @@ -407,7 +405,7 @@ public function testEmitsDataInMultipleChunksFromConnection()
$connection->write(str_repeat('*', 400000));
});

$received = Block\await($promise, null, self::TIMEOUT);
$received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));

$this->assertEquals(400000, $received);

Expand Down Expand Up @@ -449,7 +447,7 @@ public function testPipesDataBackInMultipleChunksFromConnection()
}, $reject);
});

$received = Block\await($promise, null, self::TIMEOUT);
$received = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));

$this->assertEquals(400000, $received);

Expand Down Expand Up @@ -479,7 +477,7 @@ public function testEmitsConnectionForNewTlsv11Connection()
));
$promise = $connector->connect($server->getAddress());

Block\await($promise, null, self::TIMEOUT);
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));

$server->close();
$promise->then(function (ConnectionInterface $connection) {
Expand Down Expand Up @@ -510,7 +508,7 @@ public function testEmitsErrorForClientWithTlsVersionMismatch()
$this->setExpectedException('RuntimeException', 'handshake');

try {
Block\await($promise, null, self::TIMEOUT);
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
} catch (\Exception $e) {
$server->close();

Expand All @@ -536,7 +534,7 @@ public function testServerEmitsConnectionForNewConnectionWithEncryptedCertificat
));
$connector->connect($server->getAddress());

$connection = Block\await($peer, null, self::TIMEOUT);
$connection = \React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT));

$this->assertInstanceOf('React\Socket\ConnectionInterface', $connection);

Expand All @@ -559,7 +557,7 @@ public function testClientRejectsWithErrorForServerWithInvalidCertificate()
$this->setExpectedException('RuntimeException', 'handshake');

try {
Block\await($promise, null, self::TIMEOUT);
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
} catch (\Exception $e) {
$server->close();

Expand Down Expand Up @@ -589,7 +587,7 @@ public function testServerEmitsErrorForClientWithInvalidCertificate()
$this->setExpectedException('RuntimeException', 'handshake');

try {
Block\await($peer, null, self::TIMEOUT);
\React\Async\await(\React\Promise\Timer\timeout($peer, self::TIMEOUT));
} catch (\Exception $e) {
$server->close();

Expand Down Expand Up @@ -618,7 +616,7 @@ public function testEmitsErrorForServerWithEncryptedCertificateMissingPassphrase
$this->setExpectedException('RuntimeException', 'handshake');

try {
Block\await($promise, null, self::TIMEOUT);
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
} catch (\Exception $e) {
$server->close();

Expand Down Expand Up @@ -648,7 +646,7 @@ public function testEmitsErrorForServerWithEncryptedCertificateWithInvalidPassph
$this->setExpectedException('RuntimeException', 'handshake');

try {
Block\await($promise, null, self::TIMEOUT);
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
} catch (\Exception $e) {
$server->close();

Expand All @@ -671,7 +669,7 @@ public function testEmitsErrorForConnectionWithPeerVerification()
$promise = $connector->connect($server->getAddress());
$promise->then(null, $this->expectCallableOnce());

Block\await($errorEvent, null, self::TIMEOUT);
\React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT));

$server->close();
}
Expand All @@ -696,7 +694,7 @@ public function testEmitsErrorIfConnectionIsCancelled()
$promise->cancel();
$promise->then(null, $this->expectCallableOnce());

Block\await($errorEvent, null, self::TIMEOUT);
\React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT));

$server->close();
}
Expand All @@ -717,7 +715,7 @@ public function testEmitsErrorIfConnectionIsClosedBeforeHandshake()
$stream->close();
});

$error = Block\await($errorEvent, null, 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 @@ -745,7 +743,7 @@ public function testEmitsErrorIfConnectionIsClosedWithIncompleteHandshake()
$stream->end("\x1e");
});

$error = Block\await($errorEvent, null, 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 @@ -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 = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
$this->assertInstanceOf('React\Socket\ConnectionInterface', $connection);

$server->close();
Expand All @@ -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 = \React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT));

$this->assertInstanceOf('RuntimeException', $error);

Expand Down Expand Up @@ -823,7 +821,7 @@ public function testEmitsErrorIfConnectionIsUnknownProtocolInsteadOfSecureHandsh
$stream->write("Hello world!\n");
});

$error = Block\await($errorEvent, null, self::TIMEOUT);
$error = \React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT));

$this->assertInstanceOf('RuntimeException', $error);

Expand Down
Loading