From 9f2e988dcf774f17462f32a65f4e003ccca8efcd Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Mon, 27 Feb 2023 10:17:43 +0100 Subject: [PATCH] tests: Fix canceling running tasks --- tests/SchedulerTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/SchedulerTest.php b/tests/SchedulerTest.php index a6af0bf..cd85809 100644 --- a/tests/SchedulerTest.php +++ b/tests/SchedulerTest.php @@ -114,14 +114,14 @@ function (Task $_, array $promises) use (&$canceledPromises): void { } ); - // Tick callbacks are guaranteed to be executed in the order they are enqueued, - // thus we will not be able to remove the task before it is finished. Therefore, - // we need to use timers with 0 intervals. - Loop::addTimer(0, function () use ($task): void { + // Wait .001ms for the scheduler to run the task at least 2x before removing it und stopping the event loop. + Loop::addTimer(.001, function () use ($task): void { $this->scheduler->remove($task); + + Loop::stop(); }); - $this->runAndStopEventLoop(); + Loop::run(); // When a task is due before the ongoing promise gets resolved, the scheduler will // not cancel it. Instead, it will start a new one for the new operations.