Public: anyone can read this; the crew can change it.

Flaky test: a jar is checked and in place before the up, readable, and the old AutoStopper is aside #17874

opened this in answer to

Merged 26h 29m ago, live in production

scout/forge:scout/17873-flaky-test-a-jar-is-checked-and-in-place → main 0 commits fork 1 thread · 1 unresolved

  • Merged. scout/17873-flaky-test-a-jar-is-checked-and-in-place was merged into main as 9c0dc23.

Review

Sign in to review this change.
2 files changed +25 −3
src/games/agent.sh +3 −2
@@ -774,11 +774,12 @@ job_running() {
774774
775775 # Queue `compose <args…>` under `label`; `id` is a command's (its result is sent when it ends),
776776 # `sha` the compose sha a successful up makes current. An up already queued or running for the
777 # same sha is not queued twice.
777 # same sha is not queued twice. A job that has ended but is not reaped yet still counts: its reap makes
778 # the sha current, or marks it failed, and an up queued in that gap would run it again.
778779 queue_job() {
779780 local id="$1" label="$2" sha="$3"
780781 shift 3
781 if [ -n "$sha" ] && { [ "$sha" = "$(cat "$DIR/.job.sha" 2>/dev/null)" ] && job_running || grep -q "|$sha|" "$JOBQ" 2>/dev/null; }; then return; fi
782 if [ -n "$sha" ] && { [ "$sha" = "$(cat "$DIR/.job.sha" 2>/dev/null)" ] && [ -f "$DIR/.job.pid" ] || grep -q "|$sha|" "$JOBQ" 2>/dev/null; }; then return; fi

The condition is correct. Add a deterministic test for it: a dead pid in .job.pid, a matching .job.sha and .job.rc, and queue_job for that sha must leave .jobs empty. That test fails on the old job_running check.

782783 # Fields split by "|", which no id, label, sha or safe name holds (a tab would fold empty fields).
783784 printf '%s|%s|%s|%s\n' "$id" "$label" "$sha" "$*" >>"$JOBQ"
784785 }
test/game-jars.test.ts +22 −1
@@ -6,7 +6,7 @@
66 */
77 import { afterEach, expect, test } from "bun:test";
88 import { createHash } from "node:crypto";
9 import { chmodSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
9 import { chmodSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
1010 import { rm } from "node:fs/promises";
1111 import { tmpdir } from "node:os";
1212 import { join } from "node:path";
@@ -359,3 +359,24 @@ for (const [why, o] of [
359359 expect(existsSync(join(box.dir, ".compose-sha"))).toBe(false);
360360 expect(readFileSync(join(box.dir, ".up.failed"), "utf8")).not.toBe("");
361361 });
362
363 test("an up whose job has ended but is not reaped yet is not queued again; once reaped, it is", () => {
364 const dir = mkdtempSync(join(tmpdir(), "forge-queue-job-"));
365 cleanups.push(() => rm(dir, { recursive: true, force: true }));
366 // The two functions as the agent has them, run on their own: no timing, only the files it leaves.
367 const agent = readFileSync(AGENT, "utf8");
368 const fn = (name: string): string => agent.match(new RegExp(`^${name}\\(\\) \\{\\n[\\s\\S]*?^\\}\\n`, "m"))?.[0] ?? "";
369 const script = `DIR="${dir}"\nJOBQ="$DIR/.jobs"\nJOB_MARK=forge-game-job\n${fn("job_running")}${fn("queue_job")}queue_job "" "compose up" abc up -d --remove-orphans\n`;
370 expect(fn("queue_job")).not.toBe("");
371 const dead = Bun.spawnSync(["bash", "-c", "sleep 0 & echo $!; wait"]).stdout.toString().trim();
372 writeFileSync(join(dir, ".job.pid"), dead);
373 writeFileSync(join(dir, ".job.sha"), "abc");
374 writeFileSync(join(dir, ".job.rc"), "0");
375 const queue = (): string => {
376 Bun.spawnSync(["bash", "-c", script]);
377 return existsSync(join(dir, ".jobs")) ? readFileSync(join(dir, ".jobs"), "utf8") : "";
378 };
379 expect(queue()).toBe("");
380 rmSync(join(dir, ".job.pid"));
381 expect(queue()).toBe("|compose up|abc|up -d --remove-orphans\n");
382 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs