Skip to content

Commit a6db047

Browse files
committed
Added test for concurrent output buffer control
1 parent 77ce45d commit a6db047

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
swoole_coroutine/output: concurrency
3+
--SKIPIF--
4+
<?php require __DIR__ . '/../../include/skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
require __DIR__ . '/../../include/bootstrap.php';
8+
ob_start();
9+
echo "cid 0\n";
10+
11+
Co\run(function () {
12+
ob_start();
13+
echo "cid 1\n";
14+
15+
$list = [];
16+
$n = MAX_REQUESTS;
17+
while ($n--) {
18+
$list[] = Co\go(function () {
19+
ob_start();
20+
$cid = co::getCid();
21+
echo "cid {$cid} [1]\n";
22+
usleep(random_int(1000, 5000));
23+
echo "cid {$cid} [2]\n";
24+
usleep(random_int(1000, 5000));
25+
echo "cid {$cid} [3]\n";
26+
usleep(random_int(1000, 5000));
27+
Assert::eq(
28+
ob_get_clean(),
29+
implode('', [
30+
"cid {$cid} [1]\n",
31+
"cid {$cid} [2]\n",
32+
"cid {$cid} [3]\n",
33+
])
34+
);
35+
});
36+
}
37+
co::join($list);
38+
39+
Assert::eq(ob_get_clean(), "cid 1\n");
40+
});
41+
42+
Assert::eq(ob_get_clean(), "cid 0\n");
43+
?>
44+
--EXPECT--

0 commit comments

Comments
 (0)