Public: anyone can read this; the crew can change it.
test/migrate-after.test.ts's mirror cases pass every time on a loaded check machine #4622
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/4577-test-migrate-after-test-ts-s-mirror-case → main 1 commit fork
1 file
changed +25
−10
test/migrate-after.test.ts +25 −10
| @@ -23,6 +23,7 @@ import { runGitCapture } from "../src/git/env.ts"; | ||
| 23 | 23 | import { repoDir } from "../src/git/repos.ts"; |
| 24 | 24 | import { serve, type Servers } from "../src/http/server.ts"; |
| 25 | 25 | import { settled } from "../src/origins/jobs.ts"; |
| 26 | import { pushToMirrorTarget } from "../src/origins/push-through.ts"; | |
| 26 | 27 | import { startMirrorOut } from "../src/origins/mirror-out.ts"; |
| 27 | 28 | import { forgetProviders } from "../src/origins/providers/index.ts"; |
| 28 | 29 | import { newFakeState, serveFakeForge, type FakeForge } from "./fake-origin.ts"; |
| @@ -95,6 +96,9 @@ describe("migrate: after", () => { | ||
| 95 | 96 | return { name, job, copy: `copy${n}` }; |
| 96 | 97 | }; |
| 97 | 98 | |
| 99 | /** Wakers for whoever waits on a mirror push to end. */ | |
| 100 | const pushEnded = new Set<() => void>(); | |
| 101 | ||
| 98 | 102 | const writes = () => |
| 99 | 103 | github.state.requests.filter((r) => r.method !== "GET" && r.method !== "HEAD"); |
| 100 | 104 | |
| @@ -114,7 +118,15 @@ describe("migrate: after", () => { | ||
| 114 | 118 | }); |
| 115 | 119 | if (!connected.ok) throw new Error(connected.error); |
| 116 | 120 | originId = connected.value.id; |
| 117 | stopMirror = startMirrorOut(app); | |
| 121 | stopMirror = startMirrorOut(app, async (a, repo) => { | |
| 122 | try { | |
| 123 | return await pushToMirrorTarget(a, repo); | |
| 124 | } finally { | |
| 125 | const waiting = [...pushEnded]; | |
| 126 | pushEnded.clear(); | |
| 127 | for (const wake of waiting) wake(); | |
| 128 | } | |
| 129 | }); | |
| 118 | 130 | }, 120_000); |
| 119 | 131 | |
| 120 | 132 | afterAll(async () => { |
| @@ -182,17 +194,20 @@ describe("migrate: after", () => { | ||
| 182 | 194 | expect(getRepo(app.db, "alice", copy)).toBeDefined(); |
| 183 | 195 | }); |
| 184 | 196 | |
| 185 | /** The copy's mirror target, once `ok` says the push has settled. */ | |
| 197 | /** The copy's mirror target, once `ok` says a push that has ended left it so. */ | |
| 186 | 198 | const settledTarget = async (copy: string, ok: (t: NonNullable<ReturnType<typeof getMirrorTarget>>) => boolean) => { |
| 187 | // A deadline, not a count of naps: a loaded check machine slows the push, | |
| 188 | // never the verdict. | |
| 189 | const deadline = Date.now() + 90_000; | |
| 190 | while (Date.now() < deadline) { | |
| 191 | const held = getMirrorTarget(app.db, getRepo(app.db, "alice", copy)!.id); | |
| 192 | if (held !== undefined && ok(held)) return held; | |
| 193 | await Bun.sleep(25); | |
| 199 | const id = getRepo(app.db, "alice", copy)!.id; | |
| 200 | const look = () => { | |
| 201 | const held = getMirrorTarget(app.db, id); | |
| 202 | return held !== undefined && ok(held) ? held : undefined; | |
| 203 | }; | |
| 204 | // Wait on the event, not the clock: each push that ends wakes the waiters, | |
| 205 | // and the test's own timeout is the only bound. | |
| 206 | for (;;) { | |
| 207 | const held = look(); | |
| 208 | if (held) return held; | |
| 209 | await new Promise<void>((resolve) => pushEnded.add(resolve)); | |
| 194 | 210 | } |
| 195 | throw new Error("the mirror push did not settle"); | |
| 196 | 211 | }; |
| 197 | 212 | |
| 198 | 213 | test("mirror: no write at migration, then one push to GitHub after a landing", async () => { |
new above
offline