Skip to content

Commit 28d1793

Browse files
committed
#6: * Tests for GC in the context of coroutines have been fixed.
1 parent bb6fab0 commit 28d1793

7 files changed

+21
-3
lines changed

tests/coroutine/019-coroutine_gc_basic.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Coroutine: GC handler basic functionality
44
<?php
55

66
use function Async\spawn;
7+
use function Async\suspend;
78

89
// Test that GC handler is registered and functioning
910
$coroutine = spawn(function() {
@@ -13,6 +14,8 @@ $coroutine = spawn(function() {
1314
// Force garbage collection to ensure our GC handler is called
1415
$collected = gc_collect_cycles();
1516

17+
suspend(); // Suspend to simulate coroutine lifecycle
18+
1619
// Check that coroutine completed successfully
1720
$result = $coroutine->getResult();
1821
var_dump($result);

tests/coroutine/020-coroutine_gc_with_finally.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Coroutine: GC handler with finally handlers
44
<?php
55

66
use function Async\spawn;
7+
use function Async\suspend;
78

89
// Test GC with finally handlers containing callable ZVALs
910
$coroutine = spawn(function() {
@@ -18,6 +19,8 @@ $coroutine->onFinally(function() {
1819
// Force garbage collection
1920
$collected = gc_collect_cycles();
2021

22+
suspend(); // Suspend to simulate coroutine lifecycle
23+
2124
// Wait for completion
2225
$result = $coroutine->getResult();
2326
var_dump($result);

tests/coroutine/021-coroutine_gc_with_context.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Coroutine: GC handler with context data
44
<?php
55

66
use function Async\spawn;
7+
use function Async\suspend;
78
use Async\Context;
89

910
// Test GC with coroutine context containing ZVALs
@@ -24,6 +25,8 @@ $coroutine = spawn(function() use ($context, $obj_key) {
2425
// Force garbage collection to test context ZVAL tracking
2526
$collected = gc_collect_cycles();
2627

28+
suspend(); // Suspend to simulate coroutine lifecycle
29+
2730
// Get result
2831
$result = $coroutine->getResult();
2932
var_dump($result);

tests/coroutine/022-coroutine_gc_suspended.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ $coroutine = spawn(function() {
1616
// Force garbage collection while coroutine is suspended
1717
$collected = gc_collect_cycles();
1818

19-
// Resume and complete coroutine
20-
$coroutine->resume();
19+
suspend(); // Suspend to simulate coroutine lifecycle
20+
$result = $coroutine->getResult();
21+
suspend(); // Ensure coroutine is resumed
2122
$result = $coroutine->getResult();
2223

2324
var_dump($result);

tests/coroutine/023-coroutine_gc_with_exception.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Coroutine: GC handler with exception objects
44
<?php
55

66
use function Async\spawn;
7+
use function Async\suspend;
8+
use function Async\await;
79

810
// Test GC with coroutine that has exception
911
$coroutine = spawn(function() {
@@ -15,7 +17,7 @@ $collected = gc_collect_cycles();
1517

1618
// Get exception
1719
try {
18-
$coroutine->getResult();
20+
await($coroutine);
1921
} catch (Exception $e) {
2022
var_dump($e->getMessage());
2123
}

tests/coroutine/024-coroutine_gc_multiple_zvals.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Coroutine: GC handler with multiple ZVALs
44
<?php
55

66
use function Async\spawn;
7+
use function Async\suspend;
78

89
// Test GC with coroutine containing multiple ZVALs
910
$test_data = ["key1" => "value1", "key2" => "value2"];
@@ -25,6 +26,8 @@ $coroutine->onFinally(function() {
2526
// Force garbage collection
2627
$collected = gc_collect_cycles();
2728

29+
suspend(); // Suspend to simulate coroutine lifecycle
30+
2831
// Get result
2932
$result = $coroutine->getResult();
3033
var_dump($result);

tests/coroutine/025-coroutine_gc_waker_scope.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Coroutine: GC handler with waker and scope structures
44
<?php
55

66
use function Async\spawn;
7+
use function Async\suspend;
78
use Async\Scope;
89

910
// Test GC with coroutine containing waker and scope structures
@@ -18,6 +19,8 @@ $coroutine = $scope->spawn(function() {
1819
// Force garbage collection to test waker/scope ZVAL tracking
1920
$collected = gc_collect_cycles();
2021

22+
suspend(); // Suspend to simulate coroutine lifecycle
23+
2124
// Get result
2225
$result = $coroutine->getResult();
2326
var_dump($result);

0 commit comments

Comments
 (0)