File tree Expand file tree Collapse file tree 2 files changed +35
-12
lines changed Expand file tree Collapse file tree 2 files changed +35
-12
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,9 @@ function phpt_notify($worker = WORKER_DEFAULT_NAME)
9
9
ServerClientTestCase::getInstance ()->notify ($ worker );
10
10
}
11
11
12
- function phpt_wait ($ worker = WORKER_DEFAULT_NAME )
12
+ function phpt_wait ($ worker = WORKER_DEFAULT_NAME , $ timeout = null )
13
13
{
14
- ServerClientTestCase::getInstance ()->wait ($ worker );
14
+ ServerClientTestCase::getInstance ()->wait ($ worker, $ timeout );
15
15
}
16
16
17
17
/**
@@ -121,9 +121,24 @@ class ServerClientTestCase
121
121
}
122
122
}
123
123
124
- public function wait ($ worker )
124
+ public function wait ($ worker, $ timeout = null )
125
125
{
126
- fgets ($ this ->isWorker ? STDIN : $ this ->workerStdOut [$ worker ]);
126
+ $ handle = $ this ->isWorker ? STDIN : $ this ->workerStdOut [$ worker ];
127
+ if ($ timeout === null ) {
128
+ fgets ($ handle );
129
+ return true ;
130
+ }
131
+
132
+ stream_set_blocking ($ handle , false );
133
+ $ read = [$ handle ];
134
+ $ result = stream_select ($ read , $ write , $ except , $ timeout );
135
+ if (!$ result ) {
136
+ return false ;
137
+ }
138
+
139
+ fgets ($ handle );
140
+ stream_set_blocking ($ handle , true );
141
+ return true ;
127
142
}
128
143
129
144
public function notify ($ worker )
Original file line number Diff line number Diff line change @@ -23,16 +23,21 @@ $clientCode = <<<'CODE'
23
23
24
24
$read = [$fp];
25
25
$buf = '';
26
- $printed = false;
26
+ $warmedUp = false;
27
27
while (stream_select($read, $write, $except, 1000)) {
28
28
$chunk = stream_get_contents($fp, 4096);
29
- if ($chunk !== "") {
30
- var_dump($chunk);
31
- $buf .= $chunk;
32
- } elseif (!$printed) {
33
- $printed = true;
34
- var_dump($chunk);
29
+ $buf .= $chunk;
30
+ phpt_notify('proxy');
31
+ if (!$warmedUp) {
32
+ if ($buf !== 'warmup') {
33
+ continue;
34
+ }
35
+ $warmedUp = true;
36
+ $buf = '';
37
+ phpt_notify('server');
38
+ continue;
35
39
}
40
+ var_dump($chunk);
36
41
if ($buf === 'hello, world') {
37
42
break;
38
43
}
@@ -51,6 +56,8 @@ $serverCode = <<<'CODE'
51
56
phpt_notify();
52
57
53
58
$conn = stream_socket_accept($fp);
59
+ fwrite($conn, 'warmup');
60
+ phpt_wait();
54
61
fwrite($conn, 'hello, world');
55
62
56
63
phpt_wait();
@@ -82,7 +89,7 @@ $proxyCode = <<<'CODE'
82
89
$parts = str_split($data, (int) ceil(strlen($data) / 3));
83
90
foreach ($parts as $part) {
84
91
fwrite($conn, $part);
85
- usleep(1000 );
92
+ phpt_wait(null, 1 );
86
93
}
87
94
} else {
88
95
fwrite($conn, $data);
@@ -116,4 +123,5 @@ ServerClientTestCase::getInstance()->run($clientCode, [
116
123
?>
117
124
--EXPECT--
118
125
string(0) ""
126
+ string(0) ""
119
127
string(12) "hello, world"
You can’t perform that action at this time.
0 commit comments