2
2
3
3
namespace React \Tests \Stream ;
4
4
5
- use React \Stream \DuplexResourceStream ;
6
5
use React \EventLoop \Factory ;
6
+ use React \EventLoop \LoopInterface ;
7
+ use React \Stream \DuplexResourceStream ;
7
8
use React \Stream \WritableResourceStream ;
8
9
9
10
/**
@@ -28,14 +29,14 @@ public function testUploadKilobytePlain()
28
29
29
30
$ stream ->write ("POST /post HTTP/1.0 \r\nHost: httpbin.org \r\nContent-Length: $ size \r\n\r\n" . str_repeat ('. ' , $ size ));
30
31
31
- $ loop -> run ( );
32
+ $ this -> awaitStreamClose ( $ stream , $ loop );
32
33
33
34
$ this ->assertNotEquals ('' , $ buffer );
34
35
}
35
36
36
37
public function testUploadBiggerBlockPlain ()
37
38
{
38
- $ size = 1000 * 30 ;
39
+ $ size = 50 * 1000 ;
39
40
$ stream = stream_socket_client ('tcp://httpbin.org:80 ' );
40
41
41
42
$ loop = Factory::create ();
@@ -50,7 +51,7 @@ public function testUploadBiggerBlockPlain()
50
51
51
52
$ stream ->write ("POST /post HTTP/1.0 \r\nHost: httpbin.org \r\nContent-Length: $ size \r\n\r\n" . str_repeat ('. ' , $ size ));
52
53
53
- $ loop -> run ( );
54
+ $ this -> awaitStreamClose ( $ stream , $ loop );
54
55
55
56
$ this ->assertNotEquals ('' , $ buffer );
56
57
}
@@ -72,14 +73,14 @@ public function testUploadKilobyteSecure()
72
73
73
74
$ stream ->write ("POST /post HTTP/1.0 \r\nHost: httpbin.org \r\nContent-Length: $ size \r\n\r\n" . str_repeat ('. ' , $ size ));
74
75
75
- $ loop -> run ( );
76
+ $ this -> awaitStreamClose ( $ stream , $ loop );
76
77
77
78
$ this ->assertNotEquals ('' , $ buffer );
78
79
}
79
80
80
81
public function testUploadBiggerBlockSecureRequiresSmallerChunkSize ()
81
82
{
82
- $ size = 1000 * 30000 ;
83
+ $ size = 50 * 1000 ;
83
84
$ stream = stream_socket_client ('tls://httpbin.org:443 ' );
84
85
85
86
$ loop = Factory::create ();
@@ -99,8 +100,23 @@ public function testUploadBiggerBlockSecureRequiresSmallerChunkSize()
99
100
100
101
$ stream ->write ("POST /post HTTP/1.0 \r\nHost: httpbin.org \r\nContent-Length: $ size \r\n\r\n" . str_repeat ('. ' , $ size ));
101
102
102
- $ loop -> run ( );
103
+ $ this -> awaitStreamClose ( $ stream , $ loop );
103
104
104
105
$ this ->assertNotEquals ('' , $ buffer );
105
106
}
107
+
108
+ private function awaitStreamClose (DuplexResourceStream $ stream , LoopInterface $ loop , $ timeout = 10.0 )
109
+ {
110
+ $ stream ->on ('close ' , function () use ($ loop ) {
111
+ $ loop ->stop ();
112
+ });
113
+
114
+ $ that = $ this ;
115
+ $ loop ->addTimer ($ timeout , function () use ($ loop , $ that ) {
116
+ $ loop ->stop ();
117
+ $ that ->fail ('Timed out while waiting for stream to close ' );
118
+ });
119
+
120
+ $ loop ->run ();
121
+ }
106
122
}
0 commit comments