Skip to content

Commit 0a70f05

Browse files
committed
scope/023: fix test to use delay() instead of suspend() for reliable timeout testing
suspend() only yields one tick and is not guaranteed to outlive a short timeout, making the test fragile. Replace with delay(1000) so the coroutine is genuinely blocked when the timeout fires. Also add suspend() after cancel() to let cancellation propagate before checking isFinished().
1 parent a7a4f31 commit 0a70f05

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

tests/scope/023-scope_awaitCompletion_timeout.phpt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Scope: awaitCompletion() - timeout handling
66
use function Async\spawn;
77
use function Async\suspend;
88
use function Async\timeout;
9+
use function Async\delay;
910
use function Async\await;
1011
use Async\Scope;
1112

@@ -16,9 +17,7 @@ $scope = Scope::inherit();
1617

1718
$long_running = $scope->spawn(function() {
1819
echo "long running coroutine started\n";
19-
suspend();
20-
suspend();
21-
suspend();
20+
delay(1000);
2221
echo "long running coroutine finished\n";
2322
return "delayed_result";
2423
});
@@ -40,6 +39,7 @@ await($external);
4039

4140
// Cancel the long running coroutine to clean up
4241
$long_running->cancel();
42+
suspend(); // Allow cancellation to propagate
4343

4444
echo "scope finished: " . ($scope->isFinished() ? "true" : "false") . "\n";
4545

@@ -51,7 +51,6 @@ start
5151
spawned long running coroutine
5252
long running coroutine started
5353
external waiting with timeout
54-
long running coroutine finished
5554
caught timeout as expected
5655
scope finished: true
5756
end

0 commit comments

Comments
 (0)