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

Merged opened this

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

Merged

scout/forge:scout/4696-the-rollout-test-s-socket-reconnect-verd → main 1 commit fork 1 thread · 1 unresolved

  • Merged. scout/4696-the-rollout-test-s-socket-reconnect-verd was merged into main as 1707722.

Review

Sign in to review this change.
1 file changed +17 −2
test/apps-rollout.test.ts +17 −2
@@ -28,6 +28,21 @@ import { health } from "../src/http/health.ts";
2828 import { takePresence, warmBehind, type Presence } from "../src/apps/presence.ts";
2929 import { runQuery } from "../src/boards/query.ts";
3030
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;

Duplicated with test/pull-timing.test.ts. Extract a shared test helper on the next use. Not blocking.

45
3146 /** `/` answers, `/slow` answers after a second and a half, `/ws` echoes. */
3247 const SERVER = `export const server = Bun.serve({
3348 port: Number(process.env.PORT ?? "0"),
@@ -201,7 +216,7 @@ describe("apps: through a rollout", () => {
201216 expect(closed.reason).toBe("service restart");
202217 const again = connect(a);
203218 expect(await again.opened).toBe(true);
204 expect(Date.now() - closed.at).toBeLessThan(1000);
219 expect(Date.now() - closed.at).toBeLessThan(RECONNECT_MS * loadScale());
205220 expect(await again.echo("after")).toBe("after");
206221 again.ws.close();
207222
@@ -251,7 +266,7 @@ describe("apps: through a rollout", () => {
251266 expect(closed.reason).toBe("service restart");
252267 const again = connect(next);
253268 expect(await again.opened).toBe(true);
254 expect(Date.now() - closed.at).toBeLessThan(1000);
269 expect(Date.now() - closed.at).toBeLessThan(RECONNECT_MS * loadScale());
255270 expect(await again.echo("reconnected")).toBe("reconnected");
256271 again.ws.close();
257272

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs