Skip to content

Commit 37632eb

Browse files
committed
Add a base test for coroutine interrupt.
1 parent 6d23a1c commit 37632eb

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
--TEST--
2+
swoole_coroutine: interrupt: base
3+
--SKIPIF--
4+
<?php require __DIR__ . '/../../include/skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
require __DIR__ . '/../../include/bootstrap.php';
8+
9+
Co::cancel(go(function () {
10+
var_dump(Co::sleep(1));
11+
var_dump(Co::wasCancelled());
12+
}));
13+
14+
Co::shutdown(go(function () {
15+
Co::yield();
16+
echo "never here\n";
17+
}));
18+
19+
Co::throw(go(function () {
20+
try {
21+
Co::yield();
22+
} catch (Co\Exception $e) {
23+
var_dump($e);
24+
}
25+
}));
26+
27+
?>
28+
--EXPECTF--
29+
float(1)
30+
bool(true)
31+
object(Swoole\Coroutine\Exception)#1 (12) {
32+
["message":protected]=>
33+
string(%d) "the coroutine was interrupted by an exception from cid#-1."
34+
["string":"Exception":private]=>
35+
string(%d) ""
36+
["code":protected]=>
37+
int(10016)
38+
["file":protected]=>
39+
string(%d) "%s/tests/swoole_coroutine/interrupt/base.php"
40+
["line":protected]=>
41+
int(16)
42+
["trace":"Exception":private]=>
43+
array(1) {
44+
[0]=>
45+
array(6) {
46+
["file"]=>
47+
string(%d) "%s/tests/swoole_coroutine/interrupt/base.php"
48+
["line"]=>
49+
int(16)
50+
["function"]=>
51+
string(%d) "yield"
52+
["class"]=>
53+
string(%d) "Swoole\Coroutine"
54+
["type"]=>
55+
string(%d) "::"
56+
["args"]=>
57+
array(0) {
58+
}
59+
}
60+
}
61+
["previous":"Exception":private]=>
62+
NULL
63+
["cid":protected]=>
64+
int(3)
65+
["originCid":protected]=>
66+
int(-1)
67+
["originFile":protected]=>
68+
string(%d) "%s/tests/swoole_coroutine/interrupt/base.php"
69+
["originLine":protected]=>
70+
int(20)
71+
["originTrace":protected]=>
72+
array(1) {
73+
[0]=>
74+
array(6) {
75+
["file"]=>
76+
string(%d) "%s/tests/swoole_coroutine/interrupt/base.php"
77+
["line"]=>
78+
int(20)
79+
["function"]=>
80+
string(%d) "throw"
81+
["class"]=>
82+
string(%d) "Swoole\Coroutine"
83+
["type"]=>
84+
string(%d) "::"
85+
["args"]=>
86+
array(1) {
87+
[0]=>
88+
int(3)
89+
}
90+
}
91+
}
92+
}

tests/swoole_coroutine/interrupt/cancel.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $yield = go(function () {
1616
});
1717

1818
$sleep = go(function () {
19-
if (($ret = Co::sleep(1)) === 0) {
19+
if (($ret = Co::sleep(1)) == 0) {
2020
echo "normal termination\n";
2121
} else {
2222
echo "time left {$ret}s\n";

0 commit comments

Comments
 (0)