From 2a8caf27da819fcf7543bb9cb9835640c33b40ac Mon Sep 17 00:00:00 2001 From: Dominic Griesel Date: Wed, 6 Nov 2024 21:23:58 +0100 Subject: [PATCH] fix: flaky tests --- packages/zwave-js/src/lib/driver/Task.test.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/zwave-js/src/lib/driver/Task.test.ts b/packages/zwave-js/src/lib/driver/Task.test.ts index ba7b65e6b953..5d1a38031c07 100644 --- a/packages/zwave-js/src/lib/driver/Task.test.ts +++ b/packages/zwave-js/src/lib/driver/Task.test.ts @@ -1034,9 +1034,12 @@ test("Tasks can be removed while paused", async (t) => { const order: string[] = []; scheduler.start(); + const t1WasStarted = createDeferredPromise(); + const task1 = scheduler.queueTask({ priority: TaskPriority.Normal, task: async function*() { + t1WasStarted.resolve(); order.push("1a"); yield () => wait(10); order.push("1b"); @@ -1048,7 +1051,7 @@ test("Tasks can be removed while paused", async (t) => { }, }); - await wait(1); + await t1WasStarted; // The task should have run to the first yield t.expect(order).toStrictEqual(["1a"]); @@ -1066,9 +1069,13 @@ test("Tasks can be removed while paused, part 2", async (t) => { const order: string[] = []; scheduler.start(); + const t1WasStarted = createDeferredPromise(); + const t2WasStarted = createDeferredPromise(); + const task1 = scheduler.queueTask({ priority: TaskPriority.Normal, task: async function*() { + t1WasStarted.resolve(); order.push("1a"); yield () => wait(10); order.push("1b"); @@ -1084,6 +1091,7 @@ test("Tasks can be removed while paused, part 2", async (t) => { name: "task2", priority: TaskPriority.Normal, task: async function*() { + t2WasStarted.resolve(); order.push("2a"); yield () => wait(10); order.push("2b"); @@ -1095,8 +1103,8 @@ test("Tasks can be removed while paused, part 2", async (t) => { }, }); - await wait(1); - // The tasks should have run to the first yield + await Promise.all([t1WasStarted, t2WasStarted]); + // The tasks have run to the first yield t.expect(order).toStrictEqual(["1a", "2a"]); await scheduler.removeTasks((t) => true);