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 5, 2024
1 parent ab5676b commit d1c5115
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/zwave-js/src/lib/driver/Task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,9 +1109,12 @@ test("Tasks can be removed while running", 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(10);
yield;
Expand All @@ -1137,7 +1140,7 @@ test("Tasks can be removed while running", async (t) => {
},
});

await wait(1);
await t1WasStarted;
// Task 1 should have run to the first yield,
// Task 2 should not have started yet
t.expect(order).toStrictEqual(["1a"]);
Expand All @@ -1160,9 +1163,13 @@ test("Tasks can be removed while running and paused", async (t) => {
const order: string[] = [];
scheduler.start();

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

const task1 = scheduler.queueTask({
priority: TaskPriority.Normal,
task: async function*() {
t1WasStarted.resolve();
order.push("1a");
yield () => wait(10);
order.push("1b");
Expand All @@ -1177,6 +1184,7 @@ test("Tasks can be removed while running and paused", async (t) => {
name: "task2",
priority: TaskPriority.Normal,
task: async function*() {
t2WasStarted.resolve();
order.push("2a");
await wait(10);
yield;
Expand All @@ -1188,7 +1196,7 @@ test("Tasks can be removed while running and paused", async (t) => {
},
});

await wait(1);
await Promise.all([t1WasStarted, t2WasStarted]);
// Both tasks should have run to the first yield.
t.expect(order).toStrictEqual(["1a", "2a"]);

Expand Down

0 comments on commit d1c5115

Please sign in to comment.