From dce0b33a67620342467d3d23fd0404fe3ed42b75 Mon Sep 17 00:00:00 2001 From: James Martinez Date: Sat, 19 Sep 2026 18:45:26 -0500 Subject: [PATCH] test(openworkflow): synchronize parallel crash recovery Co-authored-by: yqin0512 <284203843+yqin0512@users.noreply.github.com> --- packages/openworkflow/worker/worker.test.ts | 22 +++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/openworkflow/worker/worker.test.ts b/packages/openworkflow/worker/worker.test.ts index 8d4f3c54..72ad2347 100644 --- a/packages/openworkflow/worker/worker.test.ts +++ b/packages/openworkflow/worker/worker.test.ts @@ -389,16 +389,18 @@ describe("Worker", () => { async ({ step }) => { attemptCount++; - const [a, b] = await Promise.all([ - step.run({ name: "step-a" }, () => { - if (attemptCount > 1) return "x"; // should not happen since "a" will be cached - return "a"; - }), - step.run({ name: "step-b" }, () => { - if (attemptCount === 1) throw new Error("Simulated crash"); - return "b"; - }), - ]); + const aPromise = step.run({ name: "step-a" }, () => { + if (attemptCount > 1) return "x"; // should not happen since "a" will be cached + return "a"; + }); + const bPromise = step.run({ name: "step-b" }, async () => { + // wait for step-a's completion to be persisted before crashing. + await aPromise; + if (attemptCount === 1) throw new Error("Simulated crash"); + return "b"; + }); + + const [a, b] = await Promise.all([aPromise, bPromise]); return { a, b, attempts: attemptCount }; },