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
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
2 files
changed +25
−3
src/games/agent.sh +3 −2
| @@ -774,11 +774,12 @@ job_running() { | ||
| 774 | 774 | |
| 775 | 775 | # Queue `compose <args…>` under `label`; `id` is a command's (its result is sent when it ends), |
| 776 | 776 | # `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. | |
| 778 | 779 | queue_job() { |
| 779 | 780 | local id="$1" label="$2" sha="$3" |
| 780 | 781 | shift 3 |
| 781 | if [ -n "" ] && { [ "" = "$(cat "/.job.sha" 2>/dev/null)" ] && job_running || grep -q "||" "" 2>/dev/null; }; then return; fi | |
| 782 | if [ -n "" ] && { [ "" = "$(cat "/.job.sha" 2>/dev/null)" ] && [ -f "/.job.pid" ] || grep -q "||" "" 2>/dev/null; }; then return; fi | |
| 782 | 783 | # Fields split by "|", which no id, label, sha or safe name holds (a tab would fold empty fields). |
| 783 | 784 | printf '%s|%s|%s|%s\n' "" "" "" "$*" >>"" |
| 784 | 785 | } |
test/game-jars.test.ts +22 −1
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | import { afterEach, expect, test } from "bun:test"; |
| 8 | 8 | 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"; | |
| 10 | 10 | import { rm } from "node:fs/promises"; |
| 11 | 11 | import { tmpdir } from "node:os"; |
| 12 | 12 | import { join } from "node:path"; |
| @@ -359,3 +359,24 @@ for (const [why, o] of [ | ||
| 359 | 359 | expect(existsSync(join(box.dir, ".compose-sha"))).toBe(false); |
| 360 | 360 | expect(readFileSync(join(box.dir, ".up.failed"), "utf8")).not.toBe(""); |
| 361 | 361 | }); |
| 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 | }); |
new above
offline
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_jobfor that sha must leave .jobs empty. That test fails on the oldjob_runningcheck.