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
scout/forge:scout/965-test-app-domains-test-ts-an-app-gets-its → main 1 commit fork
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"; | ||
| 32 | 32 | import { createToken } from "../src/core/tokens.ts"; |
| 33 | 33 | import { createUser, type User } from "../src/core/users.ts"; |
| 34 | 34 | import { serve, type Servers } from "../src/http/server.ts"; |
| 35 | import { readRunLogTail } from "../src/runs/log.ts"; | |
| 35 | 36 | import { quietLogs } from "./helpers/globals.ts"; |
| 36 | 37 | |
| 37 | 38 | quietLogs(); |
| @@ -267,21 +268,36 @@ describe("an app gets its own domain", () => { | ||
| 267 | 268 | return `${(response.headers.get("set-cookie") ?? "").split(";")[0]!}; forge_mode=dev`; |
| 268 | 269 | }; |
| 269 | 270 | |
| 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 | ); | |
| 271 | 291 | const deadline = Date.now() + ms; |
| 272 | 292 | 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); | |
| 276 | 298 | } |
| 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 | }; | |
| 285 | 301 | const kinds = (prefix: string): string[] => |
| 286 | 302 | listEvents(app.db, { repoId: repo.id, limit: 100 }) |
| 287 | 303 | .map((e) => e.kind) |
| @@ -345,8 +361,7 @@ describe("an app gets its own domain", () => { | ||
| 345 | 361 | }); |
| 346 | 362 | if (!row.ok) throw new Error(row.error); |
| 347 | 363 | other = row.value; |
| 348 | const run = await settled((r) => r.env === "production"); | |
| 349 | expect(run.state).toBe("ok"); | |
| 364 | await deployed(); | |
| 350 | 365 | expect((await viaHost(`notes.${DOMAIN}`)).status).toBe(200); |
| 351 | 366 | }, 120_000); |
| 352 | 367 |
new above
offline