Skip to content

Commit 169c878

Browse files
committed
Merge branch 'tests'
2 parents ccbe18f + 2c4ffdf commit 169c878

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

tests/FactoryTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class FactoryTest extends TestCase
1212
{
1313
public function setUp()
1414
{
15-
$this->loop = React\EventLoop\Factory::create();
15+
$this->loop = new React\EventLoop\StreamSelectLoop();
1616
$factory = new React\Dns\Resolver\Factory();
1717
$resolver = $factory->create('6.6.6.6', $this->loop);
1818
$connector = new React\SocketClient\Connector($this->loop, $resolver);
@@ -102,10 +102,11 @@ public function testClientRequiresConnector()
102102
public function testPairAuthRejectDisconnects()
103103
{
104104
$server = null;
105-
$done = false;
105+
106+
$address = '127.0.0.1:1337';
106107

107108
// start a server that only sends ERR messages.
108-
$this->factory->createServer('tcp://localhost:1337')->then(function (Server $s) use (&$server) {
109+
$this->factory->createServer('tcp://' . $address)->then(function (Server $s) use (&$server) {
109110
$server = $s;
110111
});
111112

@@ -115,17 +116,18 @@ public function testPairAuthRejectDisconnects()
115116
$server->on('connection', $this->expectCallableOnce());
116117

117118
$once = $this->expectCallableOnce();
118-
$server->on('connection', function(ConnectionInterface $connection) use ($once, &$done, $server) {
119+
$server->on('connection', function(ConnectionInterface $connection) use ($once, $server) {
119120
// we expect the client to close the connection once he receives an ERR messages.
120121
$connection->on('close', $once);
121122

122-
// close the server once the client is disconnected, nobody else will connect anyway.
123-
// also, this closing the last remaining stream will end the loop.
124-
$connection->on('close', array($server, 'close'));
123+
// end the loop (stop ticking)
124+
$connection->on('close', function() use ($server) {
125+
$server->close();
126+
});
125127
});
126128

127129
// we expect the factory to fail because of the ERR message.
128-
$this->expectPromiseReject($this->factory->createClient('tcp://auth@127.0.0.1:1337'));
130+
$this->expectPromiseReject($this->factory->createClient('tcp://auth@' . $address));
129131

130132
$this->loop->run();
131133
}

0 commit comments

Comments
 (0)