test: gate run-node postbuild lock

This commit is contained in:
Shakker
2026-05-09 00:42:43 +01:00
parent 92884d0498
commit ffb83a57e5

View File

@@ -1053,10 +1053,19 @@ describe("run-node script", () => {
let activePostbuilds = 0;
let maxActivePostbuilds = 0;
let markPostbuildStarted!: () => void;
let releasePostbuild!: () => void;
const postbuildStarted = new Promise<void>((resolve) => {
markPostbuildStarted = resolve;
});
const postbuildRelease = new Promise<void>((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);