Files
orca/cloud/dev/scripts/relay-load-request-unit-boundary.test.mjs
T
Jinwoo-H 25e31c931d chore(cloud): add the relay fence broker, ops console, Terraform root, and scripts
Copies the private repository's relay side: the IAM-only fence broker, the
operations console and incident monitor, the relay Terraform root with its
backend configuration and tfvars, and the deploy/capacity/admission/rehome/
monitoring scripts the workflows call, with their contract tests, contracts,
and fixtures.

The foundation and apps Terraform roots and the API and auth services stay
private. Four surfaces that spanned both trees are narrowed to the relay side
rather than left with a dangling read: the infra runner and the root-partition
and workload-identity-condition renderers now declare only the relay root, and
the Cloud SQL rollout census drops the six app workflows that are not here.
2026-09-03 06:20:32 -04:00

53 lines
1.5 KiB
JavaScript

import assert from 'node:assert/strict'
import test from 'node:test'
import {
openRelayLoadInviteOffers,
proveRelayLoadRequestUnitBoundary
} from './relay-load-request-unit-boundary.mjs'
test('distributes the exact invite count with bounded concurrency', async () => {
let active = 0
let peak = 0
const delays = []
const calls = [0, 0, 0]
const peers = calls.map((_, index) => ({
async openInviteOffer() {
calls[index]++
active++
peak = Math.max(peak, active)
await Promise.resolve()
active--
}
}))
assert.equal(await openRelayLoadInviteOffers({
peers,
count: 8,
ratePerSecond: 2,
concurrency: 2,
delay: async (milliseconds) => { delays.push(milliseconds) },
now: () => 0
}), 8)
assert.deepEqual(calls, [3, 3, 2])
assert.ok(peak <= 2)
assert.equal(delays.length, 8)
assert.ok(Math.max(...delays) >= 3_500)
})
test('accepts only the exact request-unit exhaustion error', async () => {
assert.equal(await proveRelayLoadRequestUnitBoundary({
openInviteOffer: async () => {
throw new Error('invite offer failed: relay_capacity_exhausted')
}
}), 'relay_capacity_exhausted')
await assert.rejects(
proveRelayLoadRequestUnitBoundary({
openInviteOffer: async () => { throw new Error('control response timeout') }
}),
/not rejected safely/
)
await assert.rejects(
proveRelayLoadRequestUnitBoundary({ openInviteOffer: async () => undefined }),
/unexpectedly succeeded/
)
})