Skip to content

Commit

Permalink
Avoid using deprecated functions from clue/reactphp-block
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Aug 5, 2022
1 parent 12baa6c commit aba7c0e
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 137 deletions.
5 changes: 3 additions & 2 deletions tests/FdServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace React\Tests\Socket;

use Clue\React\Block;
use React\Promise\Promise;
use React\Socket\ConnectionInterface;
use React\Socket\FdServer;
// use function Clue\React\Block\await;
// use function React\Promise\Timer\timeout;

class FdServerTest extends TestCase
{
Expand Down Expand Up @@ -322,7 +323,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
Expand Down
20 changes: 11 additions & 9 deletions tests/FunctionalConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace React\Tests\Socket;

use Clue\React\Block;
use React\EventLoop\Loop;
use React\Promise\Deferred;
use React\Socket\ConnectionInterface;
use React\Socket\Connector;
use React\Socket\ConnectorInterface;
use React\Socket\TcpServer;
// use function Clue\React\Block\await;
// use function React\Promise\Stream\buffer;
// use function React\Promise\Timer\timeout;

class FunctionalConnectorTest extends TestCase
{
Expand All @@ -24,7 +26,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();

Expand Down Expand Up @@ -63,11 +65,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);

Expand All @@ -85,7 +87,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));
}
Expand All @@ -99,7 +101,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;
Expand All @@ -118,7 +120,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;
Expand Down Expand Up @@ -151,11 +153,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);
Expand Down
57 changes: 29 additions & 28 deletions tests/FunctionalSecureServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace React\Tests\Socket;

use Clue\React\Block;
use Evenement\EventEmitterInterface;
use React\Promise\Promise;
use React\Socket\ConnectionInterface;
use React\Socket\SecureConnector;
use React\Socket\ServerInterface;
use React\Socket\SecureServer;
use React\Socket\TcpConnector;
use React\Socket\TcpServer;
// use function Clue\React\Block\await;
// use function React\Promise\all;
// use function React\Promise\Timer\timeout;

class FunctionalSecureServerTest extends TestCase
{
Expand Down Expand Up @@ -39,7 +40,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());
Expand Down Expand Up @@ -68,7 +69,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));
Expand Down Expand Up @@ -107,7 +108,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));
Expand Down Expand Up @@ -138,7 +139,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));
Expand Down Expand Up @@ -170,7 +171,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
Expand Down Expand Up @@ -212,7 +213,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);
Expand Down Expand Up @@ -252,7 +253,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);

Expand Down Expand Up @@ -293,7 +294,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);

Expand Down Expand Up @@ -334,7 +335,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);

Expand Down Expand Up @@ -367,7 +368,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);

Expand Down Expand Up @@ -407,7 +408,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);

Expand Down Expand Up @@ -449,7 +450,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);

Expand Down Expand Up @@ -479,7 +480,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) {
Expand Down Expand Up @@ -510,7 +511,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();

Expand All @@ -536,7 +537,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);

Expand All @@ -559,7 +560,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();

Expand Down Expand Up @@ -589,7 +590,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();

Expand Down Expand Up @@ -618,7 +619,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();

Expand Down Expand Up @@ -648,7 +649,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();

Expand All @@ -671,7 +672,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();
}
Expand All @@ -696,7 +697,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();
}
Expand All @@ -717,7 +718,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);
Expand Down Expand Up @@ -745,7 +746,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);
Expand All @@ -769,7 +770,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();
Expand All @@ -794,7 +795,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);

Expand Down Expand Up @@ -823,7 +824,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);

Expand Down
Loading

0 comments on commit aba7c0e

Please sign in to comment.