Public: anyone can read this; the crew can change it.
The rollout test's socket reconnect verdict depends on order, not the check machine's clock #4709
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/4696-the-rollout-test-s-socket-reconnect-verd → main 1 commit fork 1 thread · 1 unresolved
1 file
changed +17
−2
test/apps-rollout.test.ts +17 −2
| @@ -28,6 +28,21 @@ import { health } from "../src/http/health.ts"; | ||
| 28 | 28 | import { takePresence, warmBehind, type Presence } from "../src/apps/presence.ts"; |
| 29 | 29 | import { runQuery } from "../src/boards/query.ts"; |
| 30 | 30 | |
| 31 | /** A fixed CPU workload, in ms; the `x < 0` is never true and only keeps the loop alive. */ | |
| 32 | const spin = (): number => { | |
| 33 | const t = performance.now(); | |
| 34 | let x = 0; | |
| 35 | for (let n = 0; n < 3e6; n++) x = (x + Math.sqrt(n)) % 1e9; | |
| 36 | return x < 0 ? 0 : performance.now() - t; | |
| 37 | }; | |
| 38 | const fastest = (n: number) => Math.min(...Array.from({ length: n }, spin)); | |
| 39 | /** This machine's speed at module load, idle: the reference (scale 1.0 beside itself). */ | |
| 40 | const idle = (spin(), fastest(5)); | |
| 41 | /** How much slower the machine is now than at load, 1 to 8: a busy check machine stretches the bound. */ | |
| 42 | const loadScale = () => Math.max(1, Math.min(fastest(3) / idle, 8)); | |
| 43 | /** The reconnect bound, in ms, on an idle machine. */ | |
| 44 | const RECONNECT_MS = 1000; | |
| 45 | ||
| 31 | 46 | /** `/` answers, `/slow` answers after a second and a half, `/ws` echoes. */ |
| 32 | 47 | const SERVER = `export const server = Bun.serve({ |
| 33 | 48 | port: Number(process.env.PORT ?? "0"), |
| @@ -201,7 +216,7 @@ describe("apps: through a rollout", () => { | ||
| 201 | 216 | expect(closed.reason).toBe("service restart"); |
| 202 | 217 | const again = connect(a); |
| 203 | 218 | expect(await again.opened).toBe(true); |
| 204 | expect(Date.now() - closed.at).toBeLessThan(1000); | |
| 219 | expect(Date.now() - closed.at).toBeLessThan(RECONNECT_MS * loadScale()); | |
| 205 | 220 | expect(await again.echo("after")).toBe("after"); |
| 206 | 221 | again.ws.close(); |
| 207 | 222 | |
| @@ -251,7 +266,7 @@ describe("apps: through a rollout", () => { | ||
| 251 | 266 | expect(closed.reason).toBe("service restart"); |
| 252 | 267 | const again = connect(next); |
| 253 | 268 | expect(await again.opened).toBe(true); |
| 254 | expect(Date.now() - closed.at).toBeLessThan(1000); | |
| 269 | expect(Date.now() - closed.at).toBeLessThan(RECONNECT_MS * loadScale()); | |
| 255 | 270 | expect(await again.echo("reconnected")).toBe("reconnected"); |
| 256 | 271 | again.ws.close(); |
| 257 | 272 |
new above
offline
Duplicated with test/pull-timing.test.ts. Extract a shared test helper on the next use. Not blocking.