From ffb83a57e55f8079ccc9941512375074a60c16d6 Mon Sep 17 00:00:00 2001 From: Shakker Date: Sat, 9 May 2026 00:42:43 +0100 Subject: [PATCH] test: gate run-node postbuild lock --- src/infra/run-node.test.ts | 57 +++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/infra/run-node.test.ts b/src/infra/run-node.test.ts index 53c28b3f624..36fa80d95f2 100644 --- a/src/infra/run-node.test.ts +++ b/src/infra/run-node.test.ts @@ -1053,10 +1053,19 @@ describe("run-node script", () => { let activePostbuilds = 0; let maxActivePostbuilds = 0; + let markPostbuildStarted!: () => void; + let releasePostbuild!: () => void; + const postbuildStarted = new Promise((resolve) => { + markPostbuildStarted = resolve; + }); + const postbuildRelease = new Promise((resolve) => { + releasePostbuild = resolve; + }); const runRuntimePostBuild = vi.fn(async () => { activePostbuilds += 1; maxActivePostbuilds = Math.max(maxActivePostbuilds, activePostbuilds); - await new Promise((resolve) => setTimeout(resolve, 25)); + markPostbuildStarted(); + await postbuildRelease; activePostbuilds -= 1; }); const { spawn, spawnSync } = createSpawnRecorder({ @@ -1064,28 +1073,30 @@ describe("run-node script", () => { gitStatus: "", }); - await expect( - Promise.all([ - runStatusCommand({ - tmp, - spawn, - spawnSync, - env: { - OPENCLAW_RUN_NODE_BUILD_LOCK_POLL_MS: "1", - }, - runRuntimePostBuild, - }), - runStatusCommand({ - tmp, - spawn, - spawnSync, - env: { - OPENCLAW_RUN_NODE_BUILD_LOCK_POLL_MS: "1", - }, - runRuntimePostBuild, - }), - ]), - ).resolves.toEqual([0, 0]); + const runs = Promise.all([ + runStatusCommand({ + tmp, + spawn, + spawnSync, + env: { + OPENCLAW_RUN_NODE_BUILD_LOCK_POLL_MS: "1", + }, + runRuntimePostBuild, + }), + runStatusCommand({ + tmp, + spawn, + spawnSync, + env: { + OPENCLAW_RUN_NODE_BUILD_LOCK_POLL_MS: "1", + }, + runRuntimePostBuild, + }), + ]); + + await postbuildStarted; + releasePostbuild(); + await expect(runs).resolves.toEqual([0, 0]); expect(runRuntimePostBuild).toHaveBeenCalledTimes(1); expect(maxActivePostbuilds).toBe(1);