Skip to content

Commit f956057

Browse files
authored
Merge pull request #296 from clue-labs/async
Update test suite to use new reactphp/async package instead of clue/reactphp-block
2 parents 2c60b56 + b456e9b commit f956057

18 files changed

+148
-147
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
"react/stream": "^1.2"
3636
},
3737
"require-dev": {
38-
"clue/block-react": "^1.5",
3938
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
39+
"react/async": "^4 || ^3 || ^2",
4040
"react/promise-stream": "^1.2"
4141
},
4242
"autoload": {

tests/FdServerTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace React\Tests\Socket;
44

5-
use Clue\React\Block;
65
use React\Promise\Promise;
76
use React\Socket\ConnectionInterface;
87
use React\Socket\FdServer;
@@ -322,7 +321,7 @@ public function testServerEmitsConnectionEventForNewConnection()
322321
$server->on('connection', $resolve);
323322
});
324323

325-
$connection = Block\await($promise, null, 1.0);
324+
$connection = \React\Async\await(\React\Promise\Timer\timeout($promise, 1.0));
326325

327326
/**
328327
* @var ConnectionInterface $connection

tests/FixedUriConnectorTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace React\Tests\Socket;
44

55
use React\Socket\FixedUriConnector;
6-
use React\Tests\Socket\TestCase;
76

87
class FixedUriConnectorTest extends TestCase
98
{

tests/FunctionalConnectorTest.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace React\Tests\Socket;
44

5-
use Clue\React\Block;
65
use React\EventLoop\Loop;
76
use React\Promise\Deferred;
87
use React\Socket\ConnectionInterface;
@@ -24,7 +23,7 @@ public function connectionToTcpServerShouldSucceedWithLocalhost()
2423

2524
$connector = new Connector(array());
2625

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

2928
$server->close();
3029

@@ -63,11 +62,11 @@ public function testConnectTwiceWithoutHappyEyeBallsOnlySendsSingleDnsQueryDueTo
6362
fclose($client);
6463
});
6564

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

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

@@ -85,7 +84,7 @@ public function connectionToRemoteTCP4n6ServerShouldResultInOurIP()
8584

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

88-
$ip = Block\await($this->request('dual.tlund.se', $connector), null, self::TIMEOUT);
87+
$ip = \React\Async\await(\React\Promise\Timer\timeout($this->request('dual.tlund.se', $connector), self::TIMEOUT));
8988

9089
$this->assertNotFalse(inet_pton($ip));
9190
}
@@ -99,7 +98,7 @@ public function connectionToRemoteTCP4ServerShouldResultInOurIP()
9998
$connector = new Connector(array('happy_eyeballs' => true));
10099

101100
try {
102-
$ip = Block\await($this->request('ipv4.tlund.se', $connector), null, self::TIMEOUT);
101+
$ip = \React\Async\await(\React\Promise\Timer\timeout($this->request('ipv4.tlund.se', $connector), self::TIMEOUT));
103102
} catch (\Exception $e) {
104103
$this->checkIpv4();
105104
throw $e;
@@ -118,7 +117,7 @@ public function connectionToRemoteTCP6ServerShouldResultInOurIP()
118117
$connector = new Connector(array('happy_eyeballs' => true));
119118

120119
try {
121-
$ip = Block\await($this->request('ipv6.tlund.se', $connector), null, self::TIMEOUT);
120+
$ip = \React\Async\await(\React\Promise\Timer\timeout($this->request('ipv6.tlund.se', $connector), self::TIMEOUT));
122121
} catch (\Exception $e) {
123122
$this->checkIpv6();
124123
throw $e;
@@ -151,11 +150,11 @@ public function testCancelPendingTlsConnectionDuringTlsHandshakeShouldCloseTcpCo
151150
});
152151
});
153152

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

157156
try {
158-
Block\await($promise, null, self::TIMEOUT);
157+
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
159158
$this->fail();
160159
} catch (\Exception $e) {
161160
$this->assertInstanceOf('RuntimeException', $e);

tests/FunctionalSecureServerTest.php

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace React\Tests\Socket;
44

5-
use Clue\React\Block;
6-
use Evenement\EventEmitterInterface;
75
use React\Promise\Promise;
86
use React\Socket\ConnectionInterface;
97
use React\Socket\SecureConnector;
@@ -39,7 +37,7 @@ public function testClientCanConnectToServer()
3937
$promise = $connector->connect($server->getAddress());
4038

4139
/* @var ConnectionInterface $client */
42-
$client = Block\await($promise, null, self::TIMEOUT);
40+
$client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
4341

4442
$this->assertInstanceOf('React\Socket\ConnectionInterface', $client);
4543
$this->assertEquals($server->getAddress(), $client->getRemoteAddress());
@@ -68,7 +66,7 @@ public function testClientUsesTls13ByDefaultWhenSupportedByOpenSSL()
6866
$promise = $connector->connect($server->getAddress());
6967

7068
/* @var ConnectionInterface $client */
71-
$client = Block\await($promise, null, self::TIMEOUT);
69+
$client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
7270

7371
$this->assertInstanceOf('React\Socket\Connection', $client);
7472
$this->assertTrue(isset($client->stream));
@@ -107,7 +105,7 @@ public function testClientUsesTls12WhenCryptoMethodIsExplicitlyConfiguredByClien
107105
$promise = $connector->connect($server->getAddress());
108106

109107
/* @var ConnectionInterface $client */
110-
$client = Block\await($promise, null, self::TIMEOUT);
108+
$client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
111109

112110
$this->assertInstanceOf('React\Socket\Connection', $client);
113111
$this->assertTrue(isset($client->stream));
@@ -138,7 +136,7 @@ public function testClientUsesTls12WhenCryptoMethodIsExplicitlyConfiguredByServe
138136
$promise = $connector->connect($server->getAddress());
139137

140138
/* @var ConnectionInterface $client */
141-
$client = Block\await($promise, null, self::TIMEOUT);
139+
$client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
142140

143141
$this->assertInstanceOf('React\Socket\Connection', $client);
144142
$this->assertTrue(isset($client->stream));
@@ -170,7 +168,7 @@ public function testClientUsesTls10WhenCryptoMethodIsExplicitlyConfiguredByClien
170168

171169
/* @var ConnectionInterface $client */
172170
try {
173-
$client = Block\await($promise, null, self::TIMEOUT);
171+
$client = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
174172
} catch (\RuntimeException $e) {
175173
// legacy TLS 1.0 would be considered insecure by today's standards, so skip test if connection fails
176174
// OpenSSL error messages are version/platform specific
@@ -212,7 +210,7 @@ public function testServerEmitsConnectionForClientConnection()
212210

213211
// await both client and server side end of connection
214212
/* @var ConnectionInterface[] $both */
215-
$both = Block\awaitAll(array($peer, $client), null, self::TIMEOUT);
213+
$both = \React\Async\await(\React\Promise\Timer\timeout(\React\Promise\all(array($peer, $client)), self::TIMEOUT));
216214

217215
// both ends of the connection are represented by different instances of ConnectionInterface
218216
$this->assertCount(2, $both);
@@ -252,7 +250,7 @@ public function testClientEmitsDataEventOnceForDataWrittenFromServer()
252250
}, $reject);
253251
});
254252

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

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

@@ -293,7 +291,7 @@ public function testWritesDataInMultipleChunksToConnection()
293291
}, $reject);
294292
});
295293

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

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

@@ -334,7 +332,7 @@ public function testWritesMoreDataInMultipleChunksToConnection()
334332
}, $reject);
335333
});
336334

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

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

@@ -367,7 +365,7 @@ public function testEmitsDataFromConnection()
367365
$connection->write('foo');
368366
});
369367

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

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

@@ -407,7 +405,7 @@ public function testEmitsDataInMultipleChunksFromConnection()
407405
$connection->write(str_repeat('*', 400000));
408406
});
409407

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

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

@@ -449,7 +447,7 @@ public function testPipesDataBackInMultipleChunksFromConnection()
449447
}, $reject);
450448
});
451449

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

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

@@ -479,7 +477,7 @@ public function testEmitsConnectionForNewTlsv11Connection()
479477
));
480478
$promise = $connector->connect($server->getAddress());
481479

482-
Block\await($promise, null, self::TIMEOUT);
480+
\React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
483481

484482
$server->close();
485483
$promise->then(function (ConnectionInterface $connection) {
@@ -510,7 +508,7 @@ public function testEmitsErrorForClientWithTlsVersionMismatch()
510508
$this->setExpectedException('RuntimeException', 'handshake');
511509

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

@@ -536,7 +534,7 @@ public function testServerEmitsConnectionForNewConnectionWithEncryptedCertificat
536534
));
537535
$connector->connect($server->getAddress());
538536

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

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

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

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

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

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

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

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

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

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

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

674-
Block\await($errorEvent, null, self::TIMEOUT);
672+
\React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT));
675673

676674
$server->close();
677675
}
@@ -696,7 +694,7 @@ public function testEmitsErrorIfConnectionIsCancelled()
696694
$promise->cancel();
697695
$promise->then(null, $this->expectCallableOnce());
698696

699-
Block\await($errorEvent, null, self::TIMEOUT);
697+
\React\Async\await(\React\Promise\Timer\timeout($errorEvent, self::TIMEOUT));
700698

701699
$server->close();
702700
}
@@ -717,7 +715,7 @@ public function testEmitsErrorIfConnectionIsClosedBeforeHandshake()
717715
$stream->close();
718716
});
719717

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

722720
// Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshake (ECONNRESET)
723721
$this->assertInstanceOf('RuntimeException', $error);
@@ -745,7 +743,7 @@ public function testEmitsErrorIfConnectionIsClosedWithIncompleteHandshake()
745743
$stream->end("\x1e");
746744
});
747745

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

750748
// Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshake (ECONNRESET)
751749
$this->assertInstanceOf('RuntimeException', $error);
@@ -769,7 +767,7 @@ public function testEmitsNothingIfPlaintextConnectionIsIdle()
769767
$connector = new TcpConnector();
770768
$promise = $connector->connect(str_replace('tls://', '', $server->getAddress()));
771769

772-
$connection = Block\await($promise, null, self::TIMEOUT);
770+
$connection = \React\Async\await(\React\Promise\Timer\timeout($promise, self::TIMEOUT));
773771
$this->assertInstanceOf('React\Socket\ConnectionInterface', $connection);
774772

775773
$server->close();
@@ -794,7 +792,7 @@ public function testEmitsErrorIfConnectionIsHttpInsteadOfSecureHandshake()
794792
$stream->write("GET / HTTP/1.0\r\n\r\n");
795793
});
796794

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

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

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

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

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

0 commit comments

Comments
 (0)