Public: anyone can read this; the crew can change it.
Two gated tests stop racing the deploy they watch: the run page in web-apps and the look in looks #953
scout/forge:scout/842-two-gated-tests-stop-racing-the-deploy-t → main 1 commit fork
2 files
changed +20
−7
test/looks.test.ts +8 −4
| @@ -424,6 +424,9 @@ describe("the look", () => { | ||
| 424 | 424 | }); |
| 425 | 425 | |
| 426 | 426 | test("a look is taken from `app.serving`, while the deploy's tests are still running, and a red check afterward does not remove it", async () => { |
| 427 | // The app's test holds open until this file exists, so the look is taken | |
| 428 | // while it runs however slow the runner is. | |
| 429 | const gate = join(dataDir, "release-red-test"); | |
| 427 | 430 | const branch = await commitToBranch(app, alice, repo, { |
| 428 | 431 | branch: "slow-red-test", |
| 429 | 432 | base: repo.defaultBranch, |
| @@ -435,7 +438,7 @@ describe("the look", () => { | ||
| 435 | 438 | { |
| 436 | 439 | app: { |
| 437 | 440 | run: "bun run src/server.ts", |
| 438 | test: "sleep 2 && exit 1", | |
| 441 | test: `while [ ! -f '${gate}' ]; do sleep 0.05; done; exit 1`, | |
| 439 | 442 | tty: "bun run src/tty.ts", |
| 440 | 443 | }, |
| 441 | 444 | }, |
| @@ -455,8 +458,8 @@ describe("the look", () => { | ||
| 455 | 458 | const env = `pull-${opened.value.number}`; |
| 456 | 459 | const commitOid = branch.value.commitOid; |
| 457 | 460 | |
| 458 | // Pictured well before the two-second test step could have finished — | |
| 459 | // the run is still open, checking. | |
| 461 | // Pictured while the test step is held open — the run is still open, | |
| 462 | // checking. | |
| 460 | 463 | const rows = await pictured(env, commitOid); |
| 461 | 464 | expect(rows.every((l) => l.error === null)).toBe(true); |
| 462 | 465 | const run = listRuns(app.db, repo.id, { env }).find( |
| @@ -469,8 +472,9 @@ describe("the look", () => { | ||
| 469 | 472 | expect(serving?.payload["env"]).toBe(env); |
| 470 | 473 | expect(serving?.payload["testsRunning"]).toBe(true); |
| 471 | 474 | |
| 472 | // The test then finishes red; the run fails, but the picture already | |
| 475 | // The test is released and finishes red; the run fails, but the picture already | |
| 473 | 476 | // taken of what is serving is untouched. |
| 477 | writeFileSync(gate, ""); | |
| 474 | 478 | const failed = await settled( |
| 475 | 479 | (r) => r.env === env && r.commitOid === commitOid, |
| 476 | 480 | ); |
test/web-apps.test.ts +12 −3
| @@ -351,7 +351,18 @@ describe("apps, runs and the crew on the web", () => { | ||
| 351 | 351 | "Nothing open.", |
| 352 | 352 | ); |
| 353 | 353 | |
| 354 | const page = await bodyOf(alice, `/alice/hello/runs/${run!.id}`); | |
| 354 | // The deploy may finish while the page renders: read the state before | |
| 355 | // and after, and assert the stream only when the two agree. | |
| 356 | const stateOf = () => | |
| 357 | listRuns(app.db, hello.id).find((r) => r.id === run!.id)!.state; | |
| 358 | const goingState = (s: string) => s === "queued" || s === "running"; | |
| 359 | let before = stateOf(); | |
| 360 | let page = await bodyOf(alice, `/alice/hello/runs/${run!.id}`); | |
| 361 | while (before !== stateOf() && goingState(before)) { | |
| 362 | before = stateOf(); | |
| 363 | page = await bodyOf(alice, `/alice/hello/runs/${run!.id}`); | |
| 364 | } | |
| 365 | const going = goingState(before); | |
| 355 | 366 | expect(page).toContain("<h1>Deploy production</h1>"); |
| 356 | 367 | expect(page).toContain('id="run-log"'); |
| 357 | 368 | expect(page).toContain('id="run-word"'); |
| @@ -360,8 +371,6 @@ describe("apps, runs and the crew on the web", () => { | ||
| 360 | 371 | expect(page).toContain('class="ln ln-forge"'); |
| 361 | 372 | expect(page).toContain('id="run-elapsed"'); |
| 362 | 373 | // The stream and the no-script refresh exist only while it is going. |
| 363 | const fresh = listRuns(app.db, hello.id).find((r) => r.id === run!.id)!; | |
| 364 | const going = fresh.state === "queued" || fresh.state === "running"; | |
| 365 | 374 | expect(page.includes("data-stream=")).toBe(going); |
| 366 | 375 | expect(page.includes('http-equiv="refresh"')).toBe(going); |
| 367 | 376 |
new above
offline