Skip to content

Commit f989012

Browse files
committed
Add tests
1 parent 37bae62 commit f989012

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Fibers in destructors 009: Destructor resurrects object, suspends
3+
--FILE--
4+
<?php
5+
6+
register_shutdown_function(function () {
7+
printf("Shutdown\n");
8+
});
9+
10+
class Cycle {
11+
public $self;
12+
public function __construct() {
13+
$this->self = $this;
14+
}
15+
public function __destruct() {
16+
global $ref, $f2;
17+
$ref = $this;
18+
$f2 = Fiber::getCurrent();
19+
Fiber::suspend();
20+
}
21+
}
22+
23+
$f = new Fiber(function () {
24+
global $weakRef;
25+
$weakRef = WeakReference::create(new Cycle());
26+
gc_collect_cycles();
27+
});
28+
29+
$f->start();
30+
var_dump((bool) $weakRef->get());
31+
gc_collect_cycles();
32+
$f2->resume();
33+
gc_collect_cycles();
34+
var_dump((bool) $weakRef->get());
35+
?>
36+
--EXPECT--
37+
bool(true)
38+
bool(true)
39+
Shutdown
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Fibers in destructors 010: Destructor resurrects object, suspends, unrefs
3+
--FILE--
4+
<?php
5+
6+
register_shutdown_function(function () {
7+
printf("Shutdown\n");
8+
});
9+
10+
class Cycle {
11+
public $self;
12+
public function __construct() {
13+
$this->self = $this;
14+
}
15+
public function __destruct() {
16+
global $ref, $f2;
17+
$ref = $this;
18+
$f2 = Fiber::getCurrent();
19+
Fiber::suspend();
20+
$ref = null;
21+
}
22+
}
23+
24+
$f = new Fiber(function () {
25+
global $weakRef;
26+
$weakRef = WeakReference::create(new Cycle());
27+
gc_collect_cycles();
28+
});
29+
30+
$f->start();
31+
var_dump((bool) $weakRef->get());
32+
gc_collect_cycles();
33+
$f2->resume();
34+
gc_collect_cycles();
35+
var_dump((bool) $weakRef->get());
36+
?>
37+
--EXPECT--
38+
bool(true)
39+
bool(false)
40+
Shutdown

0 commit comments

Comments
 (0)