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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/4577-test-migrate-after-test-ts-s-mirror-case → main 1 commit fork

  • Merged. scout/4577-test-migrate-after-test-ts-s-mirror-case was merged into main as 1caae5e.

Review

Sign in to review this change.
1 file changed +25 −10
test/migrate-after.test.ts +25 −10
@@ -23,6 +23,7 @@ import { runGitCapture } from "../src/git/env.ts";
2323 import { repoDir } from "../src/git/repos.ts";
2424 import { serve, type Servers } from "../src/http/server.ts";
2525 import { settled } from "../src/origins/jobs.ts";
26 import { pushToMirrorTarget } from "../src/origins/push-through.ts";
2627 import { startMirrorOut } from "../src/origins/mirror-out.ts";
2728 import { forgetProviders } from "../src/origins/providers/index.ts";
2829 import { newFakeState, serveFakeForge, type FakeForge } from "./fake-origin.ts";
@@ -95,6 +96,9 @@ describe("migrate: after", () => {
9596 return { name, job, copy: `copy${n}` };
9697 };
9798
99 /** Wakers for whoever waits on a mirror push to end. */
100 const pushEnded = new Set<() => void>();
101
98102 const writes = () =>
99103 github.state.requests.filter((r) => r.method !== "GET" && r.method !== "HEAD");
100104
@@ -114,7 +118,15 @@ describe("migrate: after", () => {
114118 });
115119 if (!connected.ok) throw new Error(connected.error);
116120 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 });
118130 }, 120_000);
119131
120132 afterAll(async () => {
@@ -182,17 +194,20 @@ describe("migrate: after", () => {
182194 expect(getRepo(app.db, "alice", copy)).toBeDefined();
183195 });
184196
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. */
186198 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));
194210 }
195 throw new Error("the mirror push did not settle");
196211 };
197212
198213 test("mirror: no write at migration, then one push to GitHub after a landing", async () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs