Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(relay): the relay test fixture polls at the relay's 200 ms [H5,C7]

Corey Olson756304669f38
diff --git a/test/relay-client-fixture.js b/test/relay-client-fixture.js
index 9e49ee54..f76cf77f 100644
--- a/test/relay-client-fixture.js
+++ b/test/relay-client-fixture.js
@@ -134,8 +134,13 @@ function childResult(root, env, argv, observedSnapshotUploads, initialSnapshotUp
export { childResult as relayFixtureChild };
-/** Start an isolated board and authorized loopback relay; a null coordinatorModel keeps its initial identity unknown. */
-export async function relayClientFixture(t, { cliChildren, coordinatorModel, accountStorageBytes } = {}) {
+/**
+ * Start an isolated board and authorized loopback relay; a null coordinatorModel keeps its initial identity unknown.
+ * The relay polls each live stream at its production 200 ms. Each poll opens the board journals, and at the 10 ms this
+ * fixture once used, a loaded machine kept the test process busy enough that browser replies queued past their
+ * deadlines (#955, #979). A case that needs a faster poll passes pollMs by name and says why.
+ */
+export async function relayClientFixture(t, { cliChildren, coordinatorModel, accountStorageBytes, pollMs = 200 } = {}) {
const scratch = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-relay-cleanup-')));
const root = join(scratch, 'repo');
const home = join(scratch, 'home');
@@ -481,7 +486,7 @@ globalThis.fetch = function tracedFetch(input, init) {
const origin = 'http://127.0.0.1:' + relayPort;
auth = createRelayAuth({ database: authDatabase, github: createGitHubClient({ ...provider.config, callbackURL: origin + '/auth/github/callback' }) });
signIn = createAuthHandler({ auth, publicOrigin: origin });
- api = createRelayHandler({ directory: join(scratch, 'relay'), auth, publicOrigin: origin, pollMs: 10, maintenanceMs: 0, accountStorageBytes, now: () => Date.now() + timeOffsetMs });
+ api = createRelayHandler({ directory: join(scratch, 'relay'), auth, publicOrigin: origin, pollMs, maintenanceMs: 0, accountStorageBytes, now: () => Date.now() + timeOffsetMs });
/** Sign a separate phone in over actual OAuth HTTP; its person session stays only in fixture RAM. */
async function phoneSession() {
if (phone) return phone;
@@ -766,7 +771,7 @@ globalThis.fetch = function tracedFetch(input, init) {
setStorageQuota(bytes) {
assert.ok(Number.isSafeInteger(bytes) && bytes > 0);
api.close();
- api = createRelayHandler({ directory: join(scratch, 'relay'), auth, publicOrigin: origin, pollMs: 10,
+ api = createRelayHandler({ directory: join(scratch, 'relay'), auth, publicOrigin: origin, pollMs,
maintenanceMs: 0, accountStorageBytes: bytes, now: () => Date.now() + timeOffsetMs });
},
/** Return a chosen HTTP refusal for snapshot writes, without inspecting the sealed body. */
diff --git a/test/relay-client-fixture.test.js b/test/relay-client-fixture.test.js
new file mode 100644
index 00000000..e5dbd768
--- /dev/null
+++ b/test/relay-client-fixture.test.js
@@ -0,0 +1,54 @@
+/** The in-process relay the client fixture starts keeps the relay's own production poll [H5,C7]. */
+import assert from 'node:assert/strict';
+import { readFileSync } from 'node:fs';
+import { test } from 'node:test';
+import { ENGINE_VERSION } from '../src/machine.js';
+import { relayClientFixture } from './relay-client-fixture.js';
+
+const PRODUCTION_POLL_MS = 200;
+const WINDOW_MS = 2_000;
+
+/**
+ * Count the fixture relay's authenticated stream polls while one live event stream stays open for a fixed window.
+ * Each poll authenticates the stream's reader again, so the count follows the poll interval: about 200 in two seconds
+ * at a 10 ms poll, about 10 at the relay's 200 ms (#979).
+ */
+async function streamPolls(box) {
+ const state = JSON.parse(readFileSync(box.linkFile, 'utf8'));
+ const controller = new AbortController();
+ const response = await fetch(`${box.origin}/api/v1/boards/${state.board}/events`, {
+ headers: { authorization: `Bearer ${state.token}`, accept: 'text/event-stream', 'x-pullboard-engine': String(ENGINE_VERSION) },
+ signal: controller.signal,
+ });
+ assert.equal(response.status, 200, 'the linked board opens a live event stream');
+ const reader = response.body.getReader();
+ const draining = (async () => { try { while (!(await reader.read()).done); } catch { /* The window closes the stream. */ } })();
+ const authenticate = box.auth.authenticate;
+ let polls = 0;
+ box.auth.authenticate = function countedAuthenticate(...args) { polls += 1; return authenticate.apply(this, args); };
+ try {
+ // budget: fixed observation window for counting the relay's own poll cadence; no throughput claim.
+ await new Promise(resolve => setTimeout(resolve, WINDOW_MS));
+ } finally {
+ box.auth.authenticate = authenticate;
+ controller.abort();
+ await draining;
+ }
+ return polls;
+}
+
+test("the relay client fixture polls at the relay's production interval by default [H5,C7]", async t => {
+ const box = await relayClientFixture(t);
+ await box.link();
+ const polls = await streamPolls(box);
+ const ceiling = Math.ceil(WINDOW_MS / PRODUCTION_POLL_MS) + 3;
+ assert.ok(polls >= 1, `the open stream is polled at all (${polls} polls in ${WINDOW_MS} ms)`);
+ assert.ok(polls <= ceiling, `the open stream is polled at most every ${PRODUCTION_POLL_MS} ms: ${polls} polls in ${WINDOW_MS} ms, at most ${ceiling}`);
+});
+
+test('a relay client fixture case can ask for a faster poll by name [H5,C7]', async t => {
+ const box = await relayClientFixture(t, { pollMs: 20 });
+ await box.link();
+ const polls = await streamPolls(box);
+ assert.ok(polls > Math.ceil(WINDOW_MS / PRODUCTION_POLL_MS) + 3, `a 20 ms poll asked for by name polls faster than the default: ${polls} polls in ${WINDOW_MS} ms`);
+});