Skip to content

Commit

Permalink
fix: flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Nov 4, 2024
1 parent 427c851 commit 16c558c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/zwave-js/src/lib/driver/Task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,12 @@ test("Higher priority tasks interrupt lower priority ones", async (t) => {
const order: string[] = [];
scheduler.start();

const t1WasStarted = createDeferredPromise<void>();

const task1 = scheduler.queueTask({
priority: TaskPriority.Normal,
task: async function*() {
t1WasStarted.resolve();
order.push("1a");
await wait(1);
yield;
Expand All @@ -194,7 +197,8 @@ test("Higher priority tasks interrupt lower priority ones", async (t) => {
order.push("1c");
},
});
await wait(0);
// The test expects that task 1 has started executing before task 2 is queued
await t1WasStarted;
const task2 = scheduler.queueTask({
priority: TaskPriority.High,
task: async function*() {
Expand Down Expand Up @@ -314,14 +318,14 @@ test("Interrupting a task with the Restart interrupt behavior restarts it comple
const order: string[] = [];
scheduler.start();

const t1HasPushed1a = createDeferredPromise<void>();
const t1WasStarted = createDeferredPromise<void>();

const task1 = scheduler.queueTask({
priority: TaskPriority.Normal,
interrupt: TaskInterruptBehavior.Restart,
task: async function*() {
t1WasStarted.resolve();
order.push("1a");
t1HasPushed1a.resolve();
await wait(1);
yield;
order.push("1b");
Expand All @@ -330,7 +334,8 @@ test("Interrupting a task with the Restart interrupt behavior restarts it comple
order.push("1c");
},
});
await t1HasPushed1a;
// The test expects that task 1 has started executing before task 2 is queued
await t1WasStarted;
const task2 = scheduler.queueTask({
priority: TaskPriority.High,
task: async function*() {
Expand Down

0 comments on commit 16c558c

Please sign in to comment.