3
3
namespace React \Tests \Socket ;
4
4
5
5
use React \Dns \Resolver \Factory as ResolverFactory ;
6
+ use React \EventLoop \Loop ;
7
+ use React \Socket \ConnectionInterface ;
6
8
use React \Socket \Connector ;
7
9
use React \Socket \DnsConnector ;
8
10
use React \Socket \SecureConnector ;
@@ -19,13 +21,15 @@ public function gettingStuffFromGoogleShouldWork()
19
21
$ connector = new Connector (array ());
20
22
21
23
$ conn = \React \Async \await ($ connector ->connect ('google.com:80 ' ));
24
+ assert ($ conn instanceof ConnectionInterface);
22
25
23
26
$ this ->assertContainsString (':80 ' , $ conn ->getRemoteAddress ());
24
27
$ this ->assertNotEquals ('google.com:80 ' , $ conn ->getRemoteAddress ());
25
28
26
29
$ conn ->write ("GET / HTTP/1.0 \r\n\r\n" );
27
30
28
31
$ response = $ this ->buffer ($ conn , self ::TIMEOUT );
32
+ assert (!$ conn ->isReadable ());
29
33
30
34
$ this ->assertMatchesRegExp ('#^HTTP/1\.0# ' , $ response );
31
35
}
@@ -40,10 +44,12 @@ public function gettingEncryptedStuffFromGoogleShouldWork()
40
44
$ secureConnector = new Connector (array ());
41
45
42
46
$ conn = \React \Async \await ($ secureConnector ->connect ('tls://google.com:443 ' ));
47
+ assert ($ conn instanceof ConnectionInterface);
43
48
44
49
$ conn ->write ("GET / HTTP/1.0 \r\n\r\n" );
45
50
46
51
$ response = $ this ->buffer ($ conn , self ::TIMEOUT );
52
+ assert (!$ conn ->isReadable ());
47
53
48
54
$ this ->assertMatchesRegExp ('#^HTTP/1\.0# ' , $ response );
49
55
}
@@ -66,10 +72,12 @@ public function gettingEncryptedStuffFromGoogleShouldWorkIfHostIsResolvedFirst()
66
72
);
67
73
68
74
$ conn = \React \Async \await ($ connector ->connect ('google.com:443 ' ));
75
+ assert ($ conn instanceof ConnectionInterface);
69
76
70
77
$ conn ->write ("GET / HTTP/1.0 \r\n\r\n" );
71
78
72
79
$ response = $ this ->buffer ($ conn , self ::TIMEOUT );
80
+ assert (!$ conn ->isReadable ());
73
81
74
82
$ this ->assertMatchesRegExp ('#^HTTP/1\.0# ' , $ response );
75
83
}
@@ -80,13 +88,15 @@ public function gettingPlaintextStuffFromEncryptedGoogleShouldNotWork()
80
88
$ connector = new Connector (array ());
81
89
82
90
$ conn = \React \Async \await ($ connector ->connect ('google.com:443 ' ));
91
+ assert ($ conn instanceof ConnectionInterface);
83
92
84
93
$ this ->assertContainsString (':443 ' , $ conn ->getRemoteAddress ());
85
94
$ this ->assertNotEquals ('google.com:443 ' , $ conn ->getRemoteAddress ());
86
95
87
96
$ conn ->write ("GET / HTTP/1.0 \r\n\r\n" );
88
97
89
98
$ response = $ this ->buffer ($ conn , self ::TIMEOUT );
99
+ assert (!$ conn ->isReadable ());
90
100
91
101
$ this ->assertDoesNotMatchRegExp ('#^HTTP/1\.0# ' , $ response );
92
102
}
@@ -148,6 +158,13 @@ public function testWaitingForRejectedConnectionShouldNotCreateAnyGarbageReferen
148
158
$ this ->markTestSkipped ('Not supported on legacy Promise v1 API ' );
149
159
}
150
160
161
+ // let loop tick for reactphp/async v4 to clean up any remaining stream resources
162
+ // @link https://github.com/reactphp/async/pull/65 reported upstream // TODO remove me once merged
163
+ if (function_exists ('React\Async\async ' )) {
164
+ \React \Async \await (\React \Promise \Timer \sleep (0 ));
165
+ Loop::run ();
166
+ }
167
+
151
168
$ connector = new Connector (array ('timeout ' => false ));
152
169
153
170
gc_collect_cycles ();
@@ -377,6 +394,7 @@ public function testSelfSignedResolvesIfVerificationIsDisabled()
377
394
));
378
395
379
396
$ conn = \React \Async \await (\React \Promise \Timer \timeout ($ connector ->connect ('tls://self-signed.badssl.com:443 ' ), self ::TIMEOUT ));
397
+ assert ($ conn instanceof ConnectionInterface);
380
398
$ conn ->close ();
381
399
382
400
// if we reach this, then everything is good
0 commit comments