Skip to content

Commit 26af3f9

Browse files
authored
test(relay): stop betting the pairing deadline against CI runners (#108)
1 parent b7c4d36 commit 26af3f9

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

relay/test/harness.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@ export async function idleTimeout(hub: DurableObjectStub, ms: number): Promise<v
107107
})
108108
}
109109

110+
/**
111+
* Bind one hub's pairing deadline, for the tests that are about the 504.
112+
*
113+
* Same shape and same rule as the two above. The pairing deadline was the
114+
* last one still bound short for the whole pool — 250 ms, on the bet that a
115+
* test's daemon always answers a round trip faster than that — and a loaded
116+
* CI runner eventually collected on the bet: four pair tests 504ed at once
117+
* while the runner stalled. Now the pool binds a deadline no test can
118+
* outlive, and the one test about the timeout binds its own short one here.
119+
*/
120+
export async function pairTimeout(hub: DurableObjectStub, ms: number): Promise<void> {
121+
await runInDurableObject(hub, (instance) => {
122+
const withEnv = instance as unknown as { env: Record<string, unknown> }
123+
withEnv.env = { ...withEnv.env, PAIR_TIMEOUT_MS: ms }
124+
})
125+
}
126+
110127
export function sleep(ms: number): Promise<void> {
111128
return new Promise((resolve) => setTimeout(resolve, ms))
112129
}

relay/test/pair.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import {
1010
freshHub,
1111
hubPath,
1212
MACHINE,
13+
pairTimeout,
1314
type Leg,
1415
} from './harness'
1516

16-
/** Mirrors the PAIR_TIMEOUT_MS binding in vitest.config.ts. */
17+
/** The deadline the one timeout test binds for itself via pairTimeout(). */
1718
const PAIR_TIMEOUT_MS = 250
1819

1920
/** The body cap, matching the daemon's own maxPairBytes (internal/daemon/pairing.go). */
@@ -292,6 +293,7 @@ describe('the cap on concurrent pairing attempts', () => {
292293
describe('a daemon that does not answer', () => {
293294
it('times out with 504 daemon did not answer', async () => {
294295
const hub = freshHub()
296+
await pairTimeout(hub, PAIR_TIMEOUT_MS)
295297
const daemon = await dial(hub, `/daemon/${MACHINE}`)
296298
const started = Date.now()
297299
const res = await post(hub, '{"token":"t"}')

relay/vitest.config.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ import { defineConfig } from 'vitest/config'
2323
* before they dial. A test that says nothing about the deadline is no longer
2424
* making a silent bet on how fast the runner is.
2525
*
26-
* The pairing deadline stays short and stays the looser of the two, because the
27-
* tests that must *not* hit it run a whole HTTP request through a WebSocket
28-
* round trip first.
26+
* The pairing deadline is bound long by the same rule, and it earned its
27+
* place the same way the handshake deadline did. It used to stay short —
28+
* 250 ms, on the reasoning that the tests that must not hit it run a whole
29+
* HTTP request through a WebSocket round trip first — and a loaded CI
30+
* runner eventually stalled past that: four pair tests 504ed in one run,
31+
* none reproducible locally. The one test about the timeout binds its own
32+
* short deadline with `pairTimeout()` before it dials.
2933
*
3034
* CLIENT_IDLE_TIMEOUT_MS is bound the same way and for the same reason: a test
3135
* client sends when its test needs it to and is otherwise silent — it sends no
@@ -41,7 +45,7 @@ export default defineConfig({
4145
bindings: {
4246
HANDSHAKE_TIMEOUT_MS: 600_000,
4347
CLIENT_IDLE_TIMEOUT_MS: 600_000,
44-
PAIR_TIMEOUT_MS: 250,
48+
PAIR_TIMEOUT_MS: 600_000,
4549
// The directory's entry cap, bound small for the same reason the
4650
// deadlines above are bound at all: the only way to test a cap is to
4751
// reach it, and reaching the production 512 is 512 sequential round

0 commit comments

Comments
 (0)