Skip to content

Commit f9b5c57

Browse files
committed
test(run-engine): make waitpoints waits event-driven (fix the original flaky race)
1 parent 7a150fa commit f9b5c57

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

internal-packages/run-engine/src/engine/tests/waitpoints.test.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,16 @@ describe("RunEngine Waitpoints", () => {
107107
const executionData = await engine.getRunExecutionData({ runId: run.id });
108108
expect(executionData?.snapshot.executionStatus).toBe("EXECUTING_WITH_WAITPOINTS");
109109

110-
await setTimeout(2_000);
110+
// Event-driven wait: the run resumes once the datetime waitpoint (~1s out) completes and the
111+
// worker unblocks it. Gate on the final state the test asserts (run EXECUTING), not just the
112+
// waitpoint status, which flips slightly earlier.
113+
await vi.waitFor(
114+
async () => {
115+
const ed = await engine.getRunExecutionData({ runId: run.id });
116+
expect(ed?.snapshot.executionStatus).toBe("EXECUTING");
117+
},
118+
{ timeout: 10_000, interval: 100 }
119+
);
111120

112121
const waitpoint2 = await prisma.waitpoint.findFirst({
113122
where: {
@@ -497,7 +506,14 @@ describe("RunEngine Waitpoints", () => {
497506
const executionData = await engine.getRunExecutionData({ runId: run.id });
498507
expect(executionData?.snapshot.executionStatus).toBe("EXECUTING_WITH_WAITPOINTS");
499508

500-
await setTimeout(750);
509+
// Event-driven wait: resume as soon as the waitpoint completes, no fixed margin.
510+
await vi.waitFor(
511+
async () => {
512+
const ed = await engine.getRunExecutionData({ runId: run.id });
513+
expect(ed?.snapshot.executionStatus).toBe("EXECUTING");
514+
},
515+
{ timeout: 10_000, interval: 100 }
516+
);
501517

502518
const executionData2 = await engine.getRunExecutionData({ runId: run.id });
503519
expect(executionData2?.snapshot.executionStatus).toBe("EXECUTING");
@@ -781,7 +797,16 @@ describe("RunEngine Waitpoints", () => {
781797
event = result;
782798
});
783799

784-
await setTimeout(1_250);
800+
// Event-driven wait: resume as soon as the timeout fires and the worker notifies, instead
801+
// of a fixed 1250ms margin against the ~1s worker poll (the original flaky race).
802+
await vi.waitFor(
803+
async () => {
804+
const ed = await engine.getRunExecutionData({ runId: run.id });
805+
expect(ed?.snapshot.executionStatus).toBe("EXECUTING");
806+
assertNonNullable(event);
807+
},
808+
{ timeout: 10_000, interval: 100 }
809+
);
785810

786811
const executionData2 = await engine.getRunExecutionData({ runId: run.id });
787812
expect(executionData2?.snapshot.executionStatus).toBe("EXECUTING");

0 commit comments

Comments
 (0)