Public: anyone can read this; the crew can change it.
A join that freezes a lent job is recorded with how long the freeze took #17959
Closed 22h 57m ago
scout/forge:scout/17950-a-join-that-freezes-a-lent-job-is-record → main 5 commits fork
10 files
changed +265
−9
- docs/features/lent-runners.md
- src/checks/lent_pause.ts
- src/checks/lent_scope.ts
- src/checks/runner_jobs.ts
- src/core/migration-pins/20261203080000-lent-pause.pin
- src/core/migrations/20261203080000-lent-pause.ts
- src/games/agent.sh
- src/http/api/runners.ts
- test/game-lend-box.test.ts
- test/lent-pause.test.ts
docs/features/lent-runners.md +7
| @@ -43,6 +43,13 @@ trust: | ||
| 43 | 43 | (`src/games/lend_fit.ts`). Its authors are limited to the repository's writers, so an outside |
| 44 | 44 | contributor's pull is never sent to it. |
| 45 | 45 | |
| 46 | When a player joins and the box's agent freezes a lent job (#17950), it tells the forge when the | |
| 47 | player joined and when the job was frozen. The forge keeps both, the gap and the job | |
| 48 | (`lent_pause`, [](../../src/checks/lent_pause.ts)) and the check's log, on the page and | |
| 49 | in the terminal's run view, says `Paused for a player who joined; frozen 0.4 s after the join`. | |
| 50 | Joins are kept per job, one row each, and at most five are told of; a later report of the same or an older join is dropped. The agent writes one `.lend.join.<job>` file per frozen job, so every guard tells its own. | |
| 51 | That is not red and not a try. | |
| 52 | ||
| 46 | 53 | A runner A owns has no scope and claims as before. A `lent-` runner enrolled before scopes takes |
| 47 | 54 | the defaults from the day it was enrolled. |
| 48 | 55 |
src/checks/lent_pause.ts added +55
| @@ -0,0 +1,55 @@ | ||
| 1 | /** | |
| 2 | * A join that froze a lent job (#17950). The box's agent reads a join from `docker events` and | |
| 3 | * freezes every job's cgroup at once; it then tells the forge when each happened (epoch | |
| 4 | * milliseconds on the box's clock, so the gap between them is the box's own). The forge keeps | |
| 5 | * both times, the gap and the job (`lent_pause`) and says it in the check's log. A pause is not a | |
| 6 | * result and not a try: nothing here touches the job's claims. | |
| 7 | */ | |
| 8 | ||
| 9 | import type { Database } from "bun:sqlite"; | |
| 10 | ||
| 11 | /** A freeze later than this after its join is not a reading to believe. */ | |
| 12 | const DELAY_MAX_MS = 3_600_000; | |
| 13 | ||
| 14 | export interface Pause { | |
| 15 | readonly joinedMs: number; | |
| 16 | readonly frozenMs: number; | |
| 17 | readonly delayMs: number; | |
| 18 | } | |
| 19 | ||
| 20 | /** The agent's `paused` field as a pause, or undefined when it is not two plausible instants. */ | |
| 21 | export function readPause(raw: unknown): Pause | undefined { | |
| 22 | if (typeof raw !== "object" || raw === null) return undefined; | |
| 23 | const { joinedMs, frozenMs } = raw as Record<string, unknown>; | |
| 24 | if (!Number.isSafeInteger(joinedMs) || !Number.isSafeInteger(frozenMs)) return undefined; | |
| 25 | const joined = joinedMs as number; | |
| 26 | const frozen = frozenMs as number; | |
| 27 | const delayMs = frozen - joined; | |
| 28 | if (joined <= 0 || delayMs < 0 || delayMs > DELAY_MAX_MS) return undefined; | |
| 29 | return { joinedMs: joined, frozenMs: frozen, delayMs }; | |
| 30 | } | |
| 31 | ||
| 32 | /** The line the check's log and details carry. */ | |
| 33 | export const pauseWords = (p: Pause): string => | |
| 34 | `Paused for a player who joined; frozen ${(p.delayMs / 1000).toFixed(1)} s after the join`; | |
| 35 | ||
| 36 | /** Joins kept per job; a job that is frozen more often than this is not told of again. */ | |
| 37 | const PAUSES_MAX = 5; | |
| 38 | ||
| 39 | /** | |
| 40 | * Keep a pause for a job: one row per job, with the joins counted (at most PAUSES_MAX), the | |
| 41 | * latest join's instant and the slowest freeze. False (rejected, nothing written) when the join | |
| 42 | * is not later than the last kept (a repeat or an old one) or the job has its share. | |
| 43 | */ | |
| 44 | export function keepPause(db: Database, job: { readonly id: string; readonly runId: string }, p: Pause): boolean { | |
| 45 | return ( | |
| 46 | db | |
| 47 | .query( | |
| 48 | `INSERT INTO lent_pause (job_id, run_id, joins, joined_ms, delay_ms) VALUES (?1, ?2, 1, ?3, ?4) | |
| 49 | ON CONFLICT (job_id) DO UPDATE SET joins = joins + 1, joined_ms = excluded.joined_ms, | |
| 50 | delay_ms = MAX(delay_ms, excluded.delay_ms) | |
| 51 | WHERE excluded.joined_ms > joined_ms AND joins < ?5`, | |
| 52 | ) | |
| 53 | .run(job.id, job.runId, p.joinedMs, p.delayMs, PAUSES_MAX).changes > 0 | |
| 54 | ); | |
| 55 | } |
src/checks/lent_scope.ts +12 −2
| @@ -155,7 +155,17 @@ export function scopeFacts( | ||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** What lent runners have run for this forge, in numbers; "" while none is lent to it. */ |
| 158 | export function lentLine(lent: { readonly runners: number; readonly coreMs: number; readonly todayCoreMs: number }): string { | |
| 158 | export function lentLine(lent: { | |
| 159 | readonly runners: number; | |
| 160 | readonly coreMs: number; | |
| 161 | readonly todayCoreMs: number; | |
| 162 | readonly pauses?: number; | |
| 163 | readonly slowestFreezeMs?: number; | |
| 164 | }): string { | |
| 159 | 165 | if (lent.runners === 0) return ""; |
| 160 | return `Lent in: ${lent.runners} lent runner${lent.runners === 1 ? "" : "s"}, ${coreMinutes(lent.coreMs)} core-min in all, ${coreMinutes(lent.todayCoreMs)} today.`; | |
| 166 | const paused = | |
| 167 | (lent.pauses ?? 0) === 0 | |
| 168 | ? "" | |
| 169 | : ` Paused for a player who joined ${lent.pauses} time${lent.pauses === 1 ? "" : "s"}; slowest freeze ${((lent.slowestFreezeMs ?? 0) / 1000).toFixed(1)} s after the join.`; | |
| 170 | return `Lent in: ${lent.runners} lent runner${lent.runners === 1 ? "" : "s"}, ${coreMinutes(lent.coreMs)} core-min in all, ${coreMinutes(lent.todayCoreMs)} today.${paused}`; | |
| 161 | 171 | } |
src/checks/runner_jobs.ts +6 −2
| @@ -281,14 +281,18 @@ export function resumeRunner(db: Database, runnerId: string): boolean { | ||
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** What lent runners have run for this forge: the line Capacity and Runners show. */ |
| 284 | export function lentIn(db: Database, now: number): { runners: number; coreMs: number; todayCoreMs: number } { | |
| 284 | export function lentIn(db: Database, now: number): { runners: number; coreMs: number; todayCoreMs: number; pauses: number; slowestFreezeMs: number } { | |
| 285 | 285 | const row = db |
| 286 | 286 | .query<{ n: number; total: number | null; today: number | null }, [string]>( |
| 287 | 287 | `SELECT COUNT(*) AS n, SUM(core_ms) AS total, SUM(CASE WHEN day = ?1 THEN day_core_ms ELSE 0 END) AS today |
| 288 | 288 | FROM check_runner WHERE scope IS NOT NULL OR name LIKE 'lent-%'`, |
| 289 | 289 | ) |
| 290 | 290 | .get(utcDay(now))!; |
| 291 | return { runners: row.n, coreMs: row.total ?? 0, todayCoreMs: row.today ?? 0 }; | |
| 291 | // Joins that froze a lent job (#17950), and the slowest freeze after one. | |
| 292 | const paused = db | |
| 293 | .query<{ n: number | null; slowest: number | null }, []>("SELECT SUM(joins) AS n, MAX(delay_ms) AS slowest FROM lent_pause") | |
| 294 | .get()!; | |
| 295 | return { runners: row.n, coreMs: row.total ?? 0, todayCoreMs: row.today ?? 0, pauses: paused.n ?? 0, slowestFreezeMs: paused.slowest ?? 0 }; | |
| 292 | 296 | } |
| 293 | 297 | |
| 294 | 298 | /** What a lent runner's greens are sampled by: its salt and how many jobs it has run. */ |
src/core/migration-pins/20261203080000-lent-pause.pin added +1
| @@ -0,0 +1,1 @@ | ||
| 1 | 99bad9cd60cae88383ee9288630c89f35155ead4441bcd16a13b464987739cba |
src/core/migrations/20261203080000-lent-pause.ts added +11
| @@ -0,0 +1,11 @@ | ||
| 1 | // Joins that froze a lent job (#17950): per job, how many were kept (at most a few), the latest | |
| 2 | // join's instant, and the slowest freeze after one. One row per job, so it cannot grow by reports. | |
| 3 | export default ` | |
| 4 | CREATE TABLE lent_pause ( | |
| 5 | job_id TEXT NOT NULL PRIMARY KEY, | |
| 6 | run_id TEXT NOT NULL, | |
| 7 | joins INTEGER NOT NULL, | |
| 8 | joined_ms INTEGER NOT NULL, | |
| 9 | delay_ms INTEGER NOT NULL | |
| 10 | ) WITHOUT ROWID; | |
| 11 | `; |
src/games/agent.sh +18 −4
| @@ -1517,11 +1517,17 @@ lend_quiet() { | ||
| 1517 | 1517 | lend_unit() { echo "/forge-job-$1.service"; } |
| 1518 | 1518 | lend_freeze() { [ -e "$(lend_unit "")/cgroup.freeze" ] && echo 1 >"$(lend_unit "")/cgroup.freeze"; return 0; } |
| 1519 | 1519 | lend_thaw() { [ -e "$(lend_unit "")/cgroup.freeze" ] && echo 0 >"$(lend_unit "")/cgroup.freeze"; return 0; } |
| 1520 | # Every job's cgroup, at once: what a join does first. | |
| 1520 | # Every job's cgroup, at once: what a join does first. The join's time (taken first) and the time | |
| 1521 | # its freeze was done go, per job, to `.lend.join.<id>` as epoch milliseconds, for that job's guard | |
| 1522 | # to tell the forge (#17950); a file is written for each cgroup actually frozen and none for the | |
| 1523 | # rest, so one job's pause never stands in another's way. | |
| 1521 | 1524 | lend_freeze_all() { |
| 1522 | local f | |
| 1525 | local f id joined | |
| 1526 | joined="$(($(date +%s%N) / 1000000))" | |
| 1523 | 1527 | for f in ""/forge-job-*.service/cgroup.freeze; do |
| 1524 | [ -e "" ] && echo 1 >"" | |
| 1528 | [ -e "" ] && echo 1 >"" || continue | |
| 1529 | id=""; id=""; id="" | |
| 1530 | [[ "" =~ ]] && echo " $(($(date +%s%N) / 1000000))" >"/.lend.join." | |
| 1525 | 1531 | done |
| 1526 | 1532 | return 0 |
| 1527 | 1533 | } |
| @@ -1689,10 +1695,17 @@ lend_step() { | ||
| 1689 | 1695 | # worker took none), the cgroup is frozen at once, and the job is stopped when memory is needed or |
| 1690 | 1696 | # it has been frozen too long. A quiet box thaws it again. |
| 1691 | 1697 | lend_guard() { |
| 1692 | local pid="$1" id="$2" beat=0 frozen=0 t | |
| 1698 | local pid="$1" id="$2" beat=0 frozen=0 t jn fz | |
| 1693 | 1699 | while kill -0 "" 2>/dev/null; do |
| 1694 | 1700 | sleep "" |
| 1695 | 1701 | t="$(date +%s)" |
| 1702 | # A join froze this job: when it joined and when it was frozen, once (#17950). | |
| 1703 | if [ -s "/.lend.join." ]; then | |
| 1704 | read -r jn fz <"/.lend.join." | |
| 1705 | rm -f "/.lend.join." | |
| 1706 | [[ "" =~ ^[0-9]{10,16}$ ]] && [[ "" =~ ^[0-9]{10,16}$ ]] && | |
| 1707 | lend_post "" "$(jq -cn --argjson j "" --argjson f "" '{paused: {joinedMs: , frozenMs: }}')" || true | |
| 1708 | fi | |
| 1696 | 1709 | if ! lend_quiet; then |
| 1697 | 1710 | lend_freeze "" |
| 1698 | 1711 | [ "" = 0 ] && frozen="" |
| @@ -1766,6 +1779,7 @@ lend_job() { | ||
| 1766 | 1779 | out="/out" |
| 1767 | 1780 | mv ".env" "/env" 2>/dev/null || : >"/env" |
| 1768 | 1781 | EVICTED=0 |
| 1782 | rm -f "/.lend.join." | |
| 1769 | 1783 | if ! lend_checkout "" "" "" "" "" ""; then |
| 1770 | 1784 | lend_clean "" "" |
| 1771 | 1785 | lend_give "" abandon "the box could not fetch the commit" |
src/http/api/runners.ts +5
| @@ -36,6 +36,7 @@ import { | ||
| 36 | 36 | wakeClaimers, |
| 37 | 37 | type RunnerResult, |
| 38 | 38 | } from "../../checks/runner_jobs.ts"; |
| 39 | import { keepPause, pauseWords, readPause } from "../../checks/lent_pause.ts"; | |
| 39 | 40 | import { readSeed } from "../../checks/runner_seeds.ts"; |
| 40 | 41 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| 41 | 42 | import { buildOf } from "../../kernel/version.ts"; |
| @@ -278,6 +279,10 @@ export function runnerRoutes(router: Router<Handler>): void { | ||
| 278 | 279 | .slice(0, LINES_MAX) |
| 279 | 280 | : []; |
| 280 | 281 | if (lines.length > 0) mine.ear.lines(str(input.step), lines); |
| 282 | // A join froze a lent job (#17950): kept with its gap, said once in the check's log. Not a | |
| 283 | // result and not a try; the report may carry the end (`interrupted`) too. | |
| 284 | const paused = mine.job.lent ? readPause(input.paused) : undefined; | |
| 285 | if (paused !== undefined && keepPause(ctx.app.db, mine.job, paused)) mine.ear.lines("", [pauseWords(paused)]); | |
| 281 | 286 | if (typeof input.interrupted === "string") { |
| 282 | 287 | if (!interruptJob(ctx.app.db, mine.job.id, token, input.interrupted, Array.isArray(input.kept) ? input.kept : [])) return notFound(); |
| 283 | 288 | wakeClaimers(ctx.app); |
test/game-lend-box.test.ts +17 −1
| @@ -294,11 +294,27 @@ describe("a join meets the job in order", () => { | ||
| 294 | 294 | "freeze at once, then stop when memory is needed; the job goes back as interrupted, never done or abandoned", |
| 295 | 295 | async () => { |
| 296 | 296 | const b = await box({ steps: [{ name: "check", command: "sleep 30" }] }, { eventAfter: 1.5 }); |
| 297 | // Another job on the box, with a guard of its own elsewhere: its pause is its own file. | |
| 298 | mkdirSync(join(b.cg, "forge-job-other.service")); | |
| 299 | writeFileSync(join(b.cg, "forge-job-other.service", "cgroup.freeze"), "0\n"); | |
| 297 | 300 | const started = Date.now(); |
| 298 | 301 | await b.run(); |
| 299 | 302 | expect(Date.now() - started).toBeLessThan(15_000); |
| 303 | // One file per frozen job: the other job's is still there for its guard; the first job's | |
| 304 | // was read and removed by its own, and no shared file is left (#17950). | |
| 305 | expect(readFileSync(join(b.dir, ".lend.join.other"), "utf8")).toMatch(/^\d{13} \d{13}\n$/); | |
| 306 | expect(existsSync(join(b.dir, ".lend.join.job1"))).toBe(false); | |
| 307 | expect(existsSync(join(b.dir, ".lend.join"))).toBe(false); | |
| 300 | 308 | const ends = b.seen.filter((s) => s.path === "/api/v1/runner/jobs/job1" && Object.keys(s.body).some((k) => k !== "step" && k !== "lines")); |
| 301 | expect(ends.map((e) => Object.keys(e.body))).toEqual([["interrupted", "kept"]]); | |
| 309 | expect(ends.filter((e) => !("paused" in e.body)).map((e) => Object.keys(e.body))).toEqual([["interrupted", "kept"]]); | |
| 310 | // The join is told with its time and the freeze's, before the stop (#17950). | |
| 311 | const said = b.seen.filter((x) => x.path === "/api/v1/runner/jobs/job1" && "paused" in x.body); | |
| 312 | expect(said).toHaveLength(1); | |
| 313 | const { joinedMs, frozenMs } = said[0]!.body["paused"] as { joinedMs: number; frozenMs: number }; | |
| 314 | expect(joinedMs).toBeGreaterThan(started); | |
| 315 | expect(frozenMs).toBeGreaterThanOrEqual(joinedMs); | |
| 316 | expect(frozenMs - joinedMs).toBeLessThan(2_000); | |
| 317 | expect(b.seen.indexOf(said[0]!)).toBeLessThan(b.seen.findIndex((x) => "interrupted" in x.body)); | |
| 302 | 318 | // Frozen when it was stopped: the freeze came first. |
| 303 | 319 | expect(readFileSync(join(b.cg, "forge-job-job1.service", "cgroup.freeze"), "utf8").trim()).toBe("1"); |
| 304 | 320 | expect(b.read("systemctl")).toContain("stop forge-job-job1.service freeze=1"); |
test/lent-pause.test.ts added +133
| @@ -0,0 +1,133 @@ | ||
| 1 | /** | |
| 2 | * A join that froze a lent job (#17950): the agent says when the player joined and when the job | |
| 3 | * was frozen; the forge keeps both with the gap and the job, and the check's log says it in plain | |
| 4 | * words. The check stays green and the pause is no try. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { openPull } from "../src/actions/pulls.ts"; | |
| 8 | import { commitToBranch } from "../src/actions/repos.ts"; | |
| 9 | import { keepPause, pauseWords, readPause } from "../src/checks/lent_pause.ts"; | |
| 10 | import { lentLine } from "../src/checks/lent_scope.ts"; | |
| 11 | import { deskOf, enrolRunner, lentIn, type RunnerJob } from "../src/checks/runner_jobs.ts"; | |
| 12 | import { startChecks } from "../src/checks/service.ts"; | |
| 13 | import { readRunLog } from "../src/runs/log.ts"; | |
| 14 | import { checkJson, checksForge } from "./helpers/checks-forge.ts"; | |
| 15 | import { quietLogs } from "./helpers/globals.ts"; | |
| 16 | import { noCanary } from "./helpers/lent.ts"; | |
| 17 | import { setLoadSource } from "../src/checks/lent_yield.ts"; | |
| 18 | ||
| 19 | quietLogs(); | |
| 20 | ||
| 21 | const PAUSES_MAX = 5; | |
| 22 | const f = checksForge("forge-lent-pause-"); | |
| 23 | ||
| 24 | const pausesOf = (jobId: string) => | |
| 25 | f.app.db | |
| 26 | .query<{ joins: number; joinedMs: number; delayMs: number }, [string]>( | |
| 27 | "SELECT joins, joined_ms AS joinedMs, delay_ms AS delayMs FROM lent_pause WHERE job_id = ?1", | |
| 28 | ) | |
| 29 | .all(jobId); | |
| 30 | ||
| 31 | const post = (path: string, token: string, body: unknown): Promise<Response> => | |
| 32 | fetch(`${f.servers.url}${path}`, { | |
| 33 | method: "POST", | |
| 34 | headers: { authorization: `Bearer ${token}`, "content-type": "application/json" }, | |
| 35 | body: JSON.stringify(body), | |
| 36 | }); | |
| 37 | ||
| 38 | beforeAll(async () => { | |
| 39 | // A lent runner waits while this machine is loaded (#16479): the test machine is idle. | |
| 40 | setLoadSource(() => 0); | |
| 41 | await f.checks.stop(); | |
| 42 | f.checks = startChecks(f.app, { forgeUrl: f.servers.url, concurrency: 1, placement: { mode: "runner", waitMs: 300 } }); | |
| 43 | const gate = await commitToBranch(f.app, f.alice, f.repo, { | |
| 44 | message: "Declare the check", | |
| 45 | files: [{ path: "forge.json", content: checkJson("echo ran") }], | |
| 46 | }); | |
| 47 | if (!gate.ok) throw new Error(JSON.stringify(gate.error)); | |
| 48 | await f.settled((r) => r.commitOid === gate.value.commitOid, 30_000); | |
| 49 | }); | |
| 50 | ||
| 51 | describe("what the agent says of a join", () => { | |
| 52 | test("two instants a little apart are a pause, said in plain words; anything else is not", () => { | |
| 53 | const p = readPause({ joinedMs: 1_800_000_000_000, frozenMs: 1_800_000_000_400 })!; | |
| 54 | expect(p).toEqual({ joinedMs: 1_800_000_000_000, frozenMs: 1_800_000_000_400, delayMs: 400 }); | |
| 55 | expect(pauseWords(p)).toBe("Paused for a player who joined; frozen 0.4 s after the join"); | |
| 56 | expect(readPause({ joinedMs: 5, frozenMs: 4 })).toBeUndefined(); | |
| 57 | expect(readPause({ joinedMs: "1", frozenMs: 2 })).toBeUndefined(); | |
| 58 | expect(readPause({ joinedMs: 1, frozenMs: 1 + 4_000_000 })).toBeUndefined(); | |
| 59 | expect(readPause(null)).toBeUndefined(); | |
| 60 | }); | |
| 61 | }); | |
| 62 | ||
| 63 | describe("what a job may be told of", () => { | |
| 64 | const job = { id: "j1", runId: "r1" }; | |
| 65 | const pause = (joinedMs: number, delayMs: number) => ({ joinedMs, frozenMs: joinedMs + delayMs, delayMs }); | |
| 66 | const rows = () => f.app.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM lent_pause").get()!.n; | |
| 67 | ||
| 68 | test("a flood of distinct joins keeps one row and at most PAUSES_MAX counted, the slowest freeze", () => { | |
| 69 | let kept = 0; | |
| 70 | for (let i = 1; i <= 500; i++) if (keepPause(f.app.db, job, pause(1_800_000_000_000 + i, i === 2 ? 900 : 100))) kept++; | |
| 71 | expect(kept).toBe(PAUSES_MAX); | |
| 72 | expect(rows()).toBe(1); | |
| 73 | expect(pausesOf("j1")).toEqual([{ joins: PAUSES_MAX, joinedMs: 1_800_000_000_005, delayMs: 900 }]); | |
| 74 | // Nor is an old join taken back in after the flood. | |
| 75 | expect(keepPause(f.app.db, { id: "j2", runId: "r1" }, pause(1_800_000_000_010, 5))).toBe(true); | |
| 76 | expect(keepPause(f.app.db, { id: "j2", runId: "r1" }, pause(1_800_000_000_009, 5))).toBe(false); | |
| 77 | f.app.db.run("DELETE FROM lent_pause"); | |
| 78 | }); | |
| 79 | }); | |
| 80 | ||
| 81 | describe("a join during a running lent job", () => { | |
| 82 | test("is kept with the job and its gap, shown in the check's log, and costs the check nothing", async () => { | |
| 83 | const lent = enrolRunner(f.app.db, "lent-box", f.alice.id); | |
| 84 | noCanary(f.app.db, lent.runner.id); | |
| 85 | const asked = post("/api/v1/runner/claim", lent.token, { wait: 20, cells: true }); | |
| 86 | await f.until(() => deskOf(f.app).claimers.size > 0, "the runner waiting in its claim"); | |
| 87 | const made = await commitToBranch(f.app, f.alice, f.repo, { branch: "pause", message: "Add p", files: [{ path: "p.txt", content: "p\n" }] }); | |
| 88 | if (!made.ok) throw new Error(JSON.stringify(made.error)); | |
| 89 | const opened = await openPull(f.app, f.alice, f.repo, { title: "pause", body: "", baseBranch: "main", headBranch: "pause" }); | |
| 90 | if (!opened.ok) throw new Error(JSON.stringify(opened.error)); | |
| 91 | const claim = (await (await asked).json()) as { job: RunnerJob; token: string }; | |
| 92 | const door = `/api/v1/runner/jobs/${claim.job.id}`; | |
| 93 | const joined = 1_800_000_000_000; | |
| 94 | ||
| 95 | expect((await post(door, claim.token, { paused: { joinedMs: joined, frozenMs: joined + 400 } })).status).toBe(200); | |
| 96 | // Said again, it is the same join; a reading that cannot be true is not kept. | |
| 97 | expect((await post(door, claim.token, { paused: { joinedMs: joined, frozenMs: joined + 400 } })).status).toBe(200); | |
| 98 | expect((await post(door, claim.token, { paused: { joinedMs: joined + 9, frozenMs: joined } })).status).toBe(200); | |
| 99 | expect(pausesOf(claim.job.id)).toEqual([{ joins: 1, joinedMs: joined, delayMs: 400 }]); | |
| 100 | ||
| 101 | // A flood of later joins over the door adds rows and log lines only up to the bound. | |
| 102 | for (let i = 1; i <= 40; i++) await post(door, claim.token, { paused: { joinedMs: joined + i, frozenMs: joined + i + 10 } }); | |
| 103 | expect(pausesOf(claim.job.id)).toEqual([{ joins: PAUSES_MAX, joinedMs: joined + PAUSES_MAX - 1, delayMs: 400 }]); | |
| 104 | ||
| 105 | expect((await post(door, claim.token, { done: { steps: [{ name: "check", ok: true, ms: 5 }], contained: true, note: "" } })).status).toBe(200); | |
| 106 | const run = await f.settled((r) => r.commitOid === made.value.commitOid, 30_000); | |
| 107 | expect(run.state).toBe("ok"); | |
| 108 | expect(run.attempt).toBe(0); | |
| 109 | const lines = readRunLog(f.app.config.dataDir, run.id).lines; | |
| 110 | expect(lines.filter((l) => l.startsWith("Paused for a player who joined"))).toHaveLength(PAUSES_MAX); | |
| 111 | expect(lines).toContain("Paused for a player who joined; frozen 0.4 s after the join"); | |
| 112 | // Runners and Capacity (page and terminal) say it too. | |
| 113 | expect(lentLine(lentIn(f.app.db, Date.now()))).toContain("Paused for a player who joined 5 times; slowest freeze 0.4 s after the join."); | |
| 114 | // Kept after the check ended and its job left the desk. | |
| 115 | expect(pausesOf(claim.job.id)).toHaveLength(1); | |
| 116 | }); | |
| 117 | ||
| 118 | test("a runner that is not lent has no pause kept", async () => { | |
| 119 | const plain = enrolRunner(f.app.db, "plain", f.alice.id); | |
| 120 | const asked = post("/api/v1/runner/claim", plain.token, { wait: 20, cells: true }); | |
| 121 | await f.until(() => deskOf(f.app).claimers.size > 0, "the runner waiting in its claim"); | |
| 122 | const made = await commitToBranch(f.app, f.alice, f.repo, { branch: "plain", message: "Add q", files: [{ path: "q.txt", content: "q\n" }] }); | |
| 123 | if (!made.ok) throw new Error(JSON.stringify(made.error)); | |
| 124 | const opened = await openPull(f.app, f.alice, f.repo, { title: "plain", body: "", baseBranch: "main", headBranch: "plain" }); | |
| 125 | if (!opened.ok) throw new Error(JSON.stringify(opened.error)); | |
| 126 | const claim = (await (await asked).json()) as { job: RunnerJob; token: string }; | |
| 127 | await post(`/api/v1/runner/jobs/${claim.job.id}`, claim.token, { paused: { joinedMs: 1_800_000_000_000, frozenMs: 1_800_000_000_100 } }); | |
| 128 | expect(pausesOf(claim.job.id)).toEqual([]); | |
| 129 | await post(`/api/v1/runner/jobs/${claim.job.id}`, claim.token, { done: { steps: [{ name: "check", ok: true, ms: 5 }], contained: true, note: "" } }); | |
| 130 | }); | |
| 131 | }); | |
| 132 | ||
| 133 | afterAll(() => setLoadSource()); |
new above
offline