-
Notifications
You must be signed in to change notification settings - Fork 5k
ci(build): keep waiting for build-cpp while a retry is queued instead of bailing on a stale errored outcome #36339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
6
commits into
main
Choose a base branch
from
farm/de87bcd2/ci-wait-for-sibling-retry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+197
−30
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
49c95e4
ci(build): keep waiting for build-cpp while a retry is queued instead…
robobun c17ae1a
[autofix.ci] apply automated fixes
autofix-ci[bot] a38ab92
preserve the spawn-error fast-fail in get()
robobun 84d7a4c
use bunExe() in the fake-agent stub instead of system node
robobun fd8b149
use the step-state vocabulary (ready/running/finished) for the retry …
robobun 3897ad1
treat a failed state read as non-terminal; name stepKey/attr in the s…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| /** | ||
| * Unit tests for the build-bun → build-cpp sibling poll in | ||
| * scripts/build/ci.ts::waitForStepOutcome(). | ||
| * | ||
| * The poll runs inside CI's rust-and-link step, so it can only be exercised by | ||
| * putting a fake `buildkite-agent` on PATH that plays back a canned sequence of | ||
| * `step get outcome` / `step get state` responses. The regression these tests | ||
| * pin down: Buildkite's `outcome` attribute reports the last *completed* job, | ||
| * so an earlier attempt that expired in the queue reads as `errored` even while | ||
| * a retry is scheduled or running. The poll must look at `state` to tell the | ||
| * two apart. | ||
| */ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { bunExe, isWindows, tempDir } from "harness"; | ||
| import { chmodSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { waitForStepOutcome } from "../../scripts/build/ci.ts"; | ||
|
|
||
| /** | ||
| * Install a fake `buildkite-agent` that serves `step get outcome|state` from | ||
| * `script[i]` on the i-th poll (clamped to the last entry), and run `fn` with | ||
| * it on PATH. `waitForStepOutcome` issues one `outcome` read then one `state` | ||
| * read per poll, so each script entry is consumed once per poll. | ||
| */ | ||
| async function withFakeAgent<T>(script: Array<{ outcome: string; state: string }>, fn: () => Promise<T>): Promise<T> { | ||
| using dir = tempDir("fake-bk-agent", { | ||
| "script.json": JSON.stringify(script), | ||
| // The real binary is Go; this stub only needs to honour | ||
| // `step get <attr> --step <key>` and count polls. | ||
| "buildkite-agent": `#!/usr/bin/env bash | ||
| set -euo pipefail | ||
| attr="\${3:-}" | ||
| n=0 | ||
| [ -f "$AGENT_DIR/calls" ] && n=$(cat "$AGENT_DIR/calls") | ||
| # One poll = outcome then state; advance the script cursor on state so both | ||
| # reads in a poll see the same entry. | ||
| if [ "$attr" = "state" ]; then | ||
| echo $((n+1)) > "$AGENT_DIR/calls" | ||
| fi | ||
| exec "$BUN_EXE" -e ' | ||
| const s = require(process.env.AGENT_DIR + "/script.json"); | ||
| const i = Math.min(+process.argv[1], s.length - 1); | ||
| process.stdout.write(s[i][process.argv[2]] ?? ""); | ||
| ' "$n" "$attr" | ||
| `, | ||
| }); | ||
| chmodSync(join(String(dir), "buildkite-agent"), 0o755); | ||
| const prev = { PATH: process.env.PATH, AGENT_DIR: process.env.AGENT_DIR, BUN_EXE: process.env.BUN_EXE }; | ||
| process.env.PATH = `${dir}:${prev.PATH}`; | ||
| process.env.AGENT_DIR = String(dir); | ||
| process.env.BUN_EXE = bunExe(); | ||
| try { | ||
| return await fn(); | ||
| } finally { | ||
| for (const [k, v] of Object.entries(prev)) { | ||
| if (v === undefined) delete process.env[k]; | ||
| else process.env[k] = v; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // The fake agent is a bash script; the Windows CI lane never runs the | ||
| // rust-and-link poll anyway (all build steps are linux-hosted). | ||
| describe.skipIf(isWindows)("waitForStepOutcome", () => { | ||
| test("resolves once the sibling passes", async () => { | ||
| await withFakeAgent( | ||
| [ | ||
| { outcome: "", state: "running" }, | ||
| { outcome: "passed", state: "passed" }, | ||
| ], | ||
| () => waitForStepOutcome("linux-x64-build-cpp", 5), | ||
| ); | ||
| }); | ||
|
|
||
| test("keeps polling while a retry is queued after an earlier error", async () => { | ||
| // Build 84838: attempt 1 expired (outcome=errored), attempt 2 sat in the | ||
| // queue (state=scheduled). The old outcome-only poll bailed at index 0. | ||
| await withFakeAgent( | ||
| [ | ||
| { outcome: "errored", state: "scheduled" }, | ||
| { outcome: "errored", state: "scheduled" }, | ||
| { outcome: "errored", state: "running" }, | ||
| { outcome: "passed", state: "passed" }, | ||
| ], | ||
| () => waitForStepOutcome("windows-x64-build-cpp", 5), | ||
| ); | ||
| }); | ||
|
|
||
| test("tolerates the gap between one attempt finishing and its retry appearing", async () => { | ||
| // A retry job is created ~1s after its predecessor ends, so one poll can | ||
| // land on a terminal state before the next attempt is scheduled. | ||
| await withFakeAgent( | ||
| [ | ||
| { outcome: "errored", state: "expired" }, | ||
| { outcome: "errored", state: "scheduled" }, | ||
| { outcome: "passed", state: "passed" }, | ||
| ], | ||
| () => waitForStepOutcome("darwin-x64-build-cpp", 5), | ||
| ); | ||
| }); | ||
|
|
||
| test("throws once the sibling is terminally failed with no retry in flight", async () => { | ||
| const err = await withFakeAgent( | ||
| [ | ||
| { outcome: "hard_failed", state: "failed" }, | ||
| { outcome: "hard_failed", state: "failed" }, | ||
| ], | ||
| () => | ||
| waitForStepOutcome("linux-x64-build-cpp", 5).then( | ||
| () => null, | ||
| e => e as Error, | ||
| ), | ||
| ); | ||
| expect(err).not.toBeNull(); | ||
| expect(String(err)).toContain("linux-x64-build-cpp hard_failed"); | ||
| }); | ||
|
|
||
| test("falls back to outcome when state is unavailable", async () => { | ||
| // `step get state` predates some agent versions returning it; an empty | ||
| // state must not mask a real failure. | ||
| const err = await withFakeAgent( | ||
| [ | ||
| { outcome: "errored", state: "" }, | ||
| { outcome: "errored", state: "" }, | ||
| ], | ||
| () => | ||
| waitForStepOutcome("linux-x64-build-cpp", 5).then( | ||
| () => null, | ||
| e => e as Error, | ||
| ), | ||
| ); | ||
| expect(err).not.toBeNull(); | ||
| expect(String(err)).toContain("errored"); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.