Public: anyone can read this; the crew can change it.

test/app-domains.test.ts: "an app gets its own domain" sets up green on a loaded runner #982

Closed opened this
Closed without merging

scout/forge:scout/965-test-app-domains-test-ts-an-app-gets-its → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
1 file changed +29 −14
test/app-domains.test.ts +29 −14
@@ -32,6 +32,7 @@ import { listRuns, type Run } from "../src/core/runs.ts";
3232 import { createToken } from "../src/core/tokens.ts";
3333 import { createUser, type User } from "../src/core/users.ts";
3434 import { serve, type Servers } from "../src/http/server.ts";
35 import { readRunLogTail } from "../src/runs/log.ts";
3536 import { quietLogs } from "./helpers/globals.ts";
3637
3738 quietLogs();
@@ -267,21 +268,36 @@ describe("an app gets its own domain", () => {
267268 return `${(response.headers.get("set-cookie") ?? "").split(";")[0]!}; forge_mode=dev`;
268269 };
269270
270 async function until<T>(read: () => T | undefined, ms = 60_000): Promise<T> {
271 /**
272 * The production deploy, once it is serving. A run stays open after that
273 * while the app's own test suite runs beside it, and on a loaded runner
274 * that suite is what takes the time; these tests need the app answering,
275 * not its tests finished. A run that fails, or never serves, is reported
276 * with its state and the tail of its log.
277 */
278 const deployed = async (ms = 45_000): Promise<Run> => {
279 const production = () =>
280 listRuns(app.db, repo.id, { kind: "deploy", limit: 50 }).find(
281 (r) => r.env === "production",
282 );
283 const report = (why: string, run: Run | undefined): Error =>
284 new Error(
285 run === undefined
286 ? `${why}: no production deploy was ever queued`
287 : `${why}: run ${run.id} is ${run.state}` +
288 (run.summary ? ` (${run.summary})` : "") +
289 `\n${readRunLogTail(dataDir, run.id, 30).lines.join("\n")}`,
290 );
271291 const deadline = Date.now() + ms;
272292 while (Date.now() < deadline) {
273 const value = read();
274 if (value !== undefined) return value;
275 await Bun.sleep(100);
293 const run = production();
294 if (run?.state === "failed" && run.servingAt === null)
295 throw report("the production deploy failed", run);
296 if (run !== undefined && run.servingAt !== null) return run;
297 await Bun.sleep(50);
276298 }
277 throw new Error("did not happen in time");
278 }
279 const settled = (where: (run: Run) => boolean) =>
280 until(() =>
281 listRuns(app.db, repo.id, { kind: "deploy", limit: 50 }).find(
282 (r) => where(r) && (r.state === "ok" || r.state === "failed"),
283 ),
284 );
299 throw report(`the production deploy was not serving in ${ms} ms`, production());
300 };
285301 const kinds = (prefix: string): string[] =>
286302 listEvents(app.db, { repoId: repo.id, limit: 100 })
287303 .map((e) => e.kind)
@@ -345,8 +361,7 @@ describe("an app gets its own domain", () => {
345361 });
346362 if (!row.ok) throw new Error(row.error);
347363 other = row.value;
348 const run = await settled((r) => r.env === "production");
349 expect(run.state).toBe("ok");
364 await deployed();
350365 expect((await viaHost(`notes.${DOMAIN}`)).status).toBe(200);
351366 }, 120_000);
352367

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs