@@ -12,7 +12,7 @@ class FactoryTest extends TestCase
12
12
{
13
13
public function setUp ()
14
14
{
15
- $ this ->loop = React \EventLoop \Factory:: create ();
15
+ $ this ->loop = new React \EventLoop \StreamSelectLoop ();
16
16
$ factory = new React \Dns \Resolver \Factory ();
17
17
$ resolver = $ factory ->create ('6.6.6.6 ' , $ this ->loop );
18
18
$ connector = new React \SocketClient \Connector ($ this ->loop , $ resolver );
@@ -102,10 +102,11 @@ public function testClientRequiresConnector()
102
102
public function testPairAuthRejectDisconnects ()
103
103
{
104
104
$ server = null ;
105
- $ done = false ;
105
+
106
+ $ address = '127.0.0.1:1337 ' ;
106
107
107
108
// 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 ) {
109
110
$ server = $ s ;
110
111
});
111
112
@@ -115,17 +116,18 @@ public function testPairAuthRejectDisconnects()
115
116
$ server ->on ('connection ' , $ this ->expectCallableOnce ());
116
117
117
118
$ once = $ this ->expectCallableOnce ();
118
- $ server ->on ('connection ' , function (ConnectionInterface $ connection ) use ($ once , & $ done , $ server ) {
119
+ $ server ->on ('connection ' , function (ConnectionInterface $ connection ) use ($ once , $ server ) {
119
120
// we expect the client to close the connection once he receives an ERR messages.
120
121
$ connection ->on ('close ' , $ once );
121
122
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
+ });
125
127
});
126
128
127
129
// 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 ));
129
131
130
132
$ this ->loop ->run ();
131
133
}
0 commit comments