Skip to content

Commit

Permalink
fix: flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Nov 6, 2024
1 parent 2efdbe3 commit 2a8caf2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/zwave-js/src/lib/driver/Task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1034,9 +1034,12 @@ test("Tasks can be removed while paused", 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");
yield () => wait(10);
order.push("1b");
Expand All @@ -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"]);

Expand All @@ -1066,9 +1069,13 @@ test("Tasks can be removed while paused, part 2", 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 @@ -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");
Expand All @@ -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);
Expand Down

0 comments on commit 2a8caf2

Please sign in to comment.