From ac019ef8dfb3f1a8fe683bf6c4f65ca68fae301b Mon Sep 17 00:00:00 2001 From: OrcaWin Date: Fri, 13 Nov 2026 05:53:13 -0800 Subject: [PATCH] test: remove low-value relay assignment coverage (#42031) Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com> --- ...ignment-dead-reserve-cell-postgres.test.ts | 58 -------- ...ignment-deployment-status-postgres.test.ts | 23 --- .../assignment-headroom-scope.test.ts | 62 ++------ .../assignment-home-cell-unavailable.test.ts | 9 -- .../assignment-inventory-snapshot.test.ts | 108 -------------- ...isolated-cell-replacement-postgres.test.ts | 5 +- .../src/assignment/assignment-lease.test.ts | 138 +----------------- .../dead-cell-evacuation-precheck.test.ts | 20 --- .../public-assignment-circuit-breaker.test.ts | 49 ------- .../public-assignment-reconnect-lane.test.ts | 20 --- .../idle-regional-rehome-store.test.ts | 14 -- .../idle-regional-rehome-window.test.ts | 19 --- 12 files changed, 16 insertions(+), 509 deletions(-) delete mode 100644 cloud/apps/relay/src/assignment/assignment-inventory-snapshot.test.ts delete mode 100644 cloud/apps/relay/src/assignment/public-admission/public-assignment-circuit-breaker.test.ts diff --git a/cloud/apps/relay/src/assignment/assignment-dead-reserve-cell-postgres.test.ts b/cloud/apps/relay/src/assignment/assignment-dead-reserve-cell-postgres.test.ts index 04c62668610..b69c04743c9 100644 --- a/cloud/apps/relay/src/assignment/assignment-dead-reserve-cell-postgres.test.ts +++ b/cloud/apps/relay/src/assignment/assignment-dead-reserve-cell-postgres.test.ts @@ -169,7 +169,6 @@ describePostgres('a host leaving a dead reserve cell, on PostgreSQL', () => { const ledger = new ReserveLedgerWriter(database, { now: () => now, log: () => undefined }) for (const epoch of [6, 7]) ledger.enqueue({ userId: USER, relayHostId: host, cellId: dead.id, epoch }) await ledger.flush() - expect(ledger.pending()).toBe(0) expect(await rowOf(host)).toEqual({ cell_id: live.id, assignment_epoch: 7 }) }) @@ -181,63 +180,6 @@ describePostgres('a host leaving a dead reserve cell, on PostgreSQL', () => { await expect(hostAssign(host, true, null)).rejects.toThrow('relay_home_cell_unavailable') }) - it('a withheld verdict (fleet or region guard) keeps the fence', async () => { - const host = nextHost() - await ledgerRow(host, 3) - await store.setCellAdmitMode(dead.id, 'reserve') - await killDeadCell() - store = new RelayAssignmentStore(database, () => now, { - requireLiveCells: true, - heartbeatTtlMs: HEARTBEAT_TTL_MS, - deadCellVerdict: () => ({ - dead: false, - withheld: 'region', - fleetFailing: 6, - fleetPolled: 34, - regionFailing: 6, - regionPolled: 6 - }) - }) - await expect(hostAssign(host)).rejects.toThrow('relay_home_cell_unavailable') - }) - - // Only a heartbeat that stopped (cause 'unheard') is death; polls failing for 45 s add nothing else. - it('a cell heartbeating but not ready keeps its hosts, however long its polls fail', async () => { - const host = nextHost() - await ledgerRow(host, 3) - await store.setCellAdmitMode(dead.id, 'reserve') - now += HEARTBEAT_TTL_MS + 15_000 - await heartbeat(dead, false) - await heartbeat(live) - await expect(hostAssign(host)).rejects.toThrow('relay_home_cell_unavailable') - expect(await rowOf(host)).toEqual({ cell_id: dead.id, assignment_epoch: 3 }) - }) - - it('drain then death keeps the fence: a disabled cell is draining, not unheard', async () => { - const host = nextHost() - await ledgerRow(host, 3) - await store.setCellAdmitMode(dead.id, 'reserve') - await database.query(`UPDATE relay_cells SET enabled = 0 WHERE cell_id = ?`, [dead.id]) - try { - await killDeadCell() - await expect(hostAssign(host)).rejects.toThrow('relay_home_cell_unavailable') - expect(await rowOf(host)).toEqual({ cell_id: dead.id, assignment_epoch: 3 }) - } finally { - await database.query(`UPDATE relay_cells SET enabled = 1 WHERE cell_id = ?`, [dead.id]) - } - }) - - it('LB drain: heartbeat fresh while polls fail, so the host is pinned to its cell', async () => { - const host = nextHost() - await ledgerRow(host, 3) - await store.setCellAdmitMode(dead.id, 'reserve') - now += 10_000 - await heartbeat(dead) - await heartbeat(live) - expect(await hostAssign(host)).toMatchObject({ cellId: dead.id, assignmentEpoch: 3 }) - expect(await rowOf(host)).toEqual({ cell_id: dead.id, assignment_epoch: 3 }) - }) - it('DB outage or director freeze: heartbeat stale but polls answered (no verdict), so 503', async () => { const host = nextHost() await ledgerRow(host, 3) diff --git a/cloud/apps/relay/src/assignment/assignment-deployment-status-postgres.test.ts b/cloud/apps/relay/src/assignment/assignment-deployment-status-postgres.test.ts index ad45a84cba9..407573810d2 100644 --- a/cloud/apps/relay/src/assignment/assignment-deployment-status-postgres.test.ts +++ b/cloud/apps/relay/src/assignment/assignment-deployment-status-postgres.test.ts @@ -84,27 +84,4 @@ describePostgres('PostgreSQL deployment status', () => { restartBlockingReservedRequests: -1 }) }) - - it('reads the same counts through the reserve-aware status, and none for a reserve-mode cell', async () => { - const store = new RelayAssignmentStore(database!, () => 100) - const reserveCell = { ...cell, id: `${cell.id}-reserve`, url: 'https://deployment-status-reserve.example.com' } - await store.reconcileCells([cell, reserveCell]) - await store.assign({ userId: 'aware-user', relayHostId: 'd1e2f3a4b5c6' }) - expect(await store.reserveAwareCellDeploymentStatus(cell.id)).toEqual({ - admitMode: 'db', - status: await store.cellDeploymentStatus(cell.id) - }) - - await store.setCellAdmitMode(reserveCell.id, 'reserve') - await expect(store.cellDeploymentStatus(reserveCell.id)).rejects.toThrow('cell_in_reserve_mode') - const reserve = await store.reserveAwareCellDeploymentStatus(reserveCell.id) - expect(reserve).toMatchObject({ - admitMode: 'reserve', - status: { cellId: reserveCell.id, cellUrl: reserveCell.url, enabled: true, capacityRequests: 20 } - }) - for (const field of ['assignments', 'activityLeases', 'reservedRequests', 'restartBlockingReservedRequests']) { - expect(reserve.status).not.toHaveProperty(field) - } - await expect(store.reserveAwareCellDeploymentStatus('missing-cell')).rejects.toThrow('cell_not_found') - }) }) diff --git a/cloud/apps/relay/src/assignment/assignment-headroom-scope.test.ts b/cloud/apps/relay/src/assignment/assignment-headroom-scope.test.ts index d7ba52e9682..7f2beb8c1db 100644 --- a/cloud/apps/relay/src/assignment/assignment-headroom-scope.test.ts +++ b/cloud/apps/relay/src/assignment/assignment-headroom-scope.test.ts @@ -3,42 +3,27 @@ import { RelayAssignmentStore } from './assignment-store.js' import { openInMemoryRelayDatabase, type RelayDatabase } from '../database/database.js' const NOW = 100_000 -const CELL_COUNT = 32 const identity = { userId: 'headroom-user', relayHostId: 'headroomhost0001' } -function observeHeadroom(database: RelayDatabase, rowCounts: number[]): RelayDatabase { - return { - dialect: database.dialect, - async query(sql, params) { - const rows = await database.query(sql, params) - if (sql.includes('FROM relay_cell_connection_limits limits')) rowCounts.push(rows.length) - return rows - }, - queryLocked: (sql, params, options) => database.queryLocked(sql, params, options), - transaction: (operation, options) => - database.transaction((transaction) => operation(observeHeadroom(transaction, rowCounts)), options), - close: () => database.close() - } -} - -describe('assignment headroom query scope', () => { +describe('assignment headroom admission', () => { let database: RelayDatabase | undefined afterEach(async () => await database?.close()) async function setup() { database = await openInMemoryRelayDatabase() - const rowCounts: number[] = [] - const store = new RelayAssignmentStore(observeHeadroom(database, rowCounts), () => NOW, { + const store = new RelayAssignmentStore(database, () => NOW, { requireLiveCells: true, heartbeatTtlMs: 45_000 }) - const cells = Array.from({ length: CELL_COUNT }, (_, index) => ({ - id: `cell-${String(index).padStart(2, '0')}`, - url: `https://cell-${index}.example.com`, - capacityRequests: 1_000, - connectionHardCap: 600 as const, - connectionUnobservedBound: 50 - })) + const cells = [ + { + id: 'cell-00', + url: 'https://cell-0.example.com', + capacityRequests: 1_000, + connectionHardCap: 600 as const, + connectionUnobservedBound: 50 + } + ] await store.reconcileCells(cells) for (const cell of cells) { await store.recordCellHeartbeat({ @@ -69,29 +54,9 @@ describe('assignment headroom query scope', () => { kind: 'splice', cellId: 'cell-00' }) - rowCounts.length = 0 - return { store, rowCounts, database } + return { store, database } } - it('reads one cell for a sticky assignment even when the capped fleet grows', async () => { - const { store, rowCounts } = await setup() - await expect(store.assign(identity)).resolves.toMatchObject({ - ...identity, - cellId: 'cell-00', - assignmentEpoch: 1 - }) - console.info('sticky headroom rows', { fleetCells: CELL_COUNT, rowCounts }) - expect(rowCounts).toEqual([1]) - }) - - it('still considers the full fleet for a new placement', async () => { - const { store, rowCounts } = await setup() - await expect( - store.assign({ userId: 'new-user', relayHostId: 'newheadroomhost1' }) - ).resolves.toMatchObject({ cellId: 'cell-01', assignmentEpoch: 1 }) - expect(rowCounts).toEqual([CELL_COUNT]) - }) - it.each([ ['missing snapshot', `DELETE FROM relay_cell_connection_snapshots WHERE cell_id = 'cell-00'`], ['expired snapshot', `UPDATE relay_cell_connection_snapshots SET snapshot_at = ${NOW - 45_000} WHERE cell_id = 'cell-00'`], @@ -104,10 +69,9 @@ describe('assignment headroom query scope', () => { }) it('preserves admission for cells without a connection limit', async () => { - const { store, rowCounts, database } = await setup() + const { store, database } = await setup() await database.query(`DELETE FROM relay_cell_connection_limits WHERE cell_id = 'cell-00'`) await expect(store.assign(identity)).resolves.toMatchObject({ cellId: 'cell-00' }) - expect(rowCounts).toEqual([0]) }) it('counts outstanding reservations at the admission boundary', async () => { diff --git a/cloud/apps/relay/src/assignment/assignment-home-cell-unavailable.test.ts b/cloud/apps/relay/src/assignment/assignment-home-cell-unavailable.test.ts index 45cf0bf704c..3227d64e82b 100644 --- a/cloud/apps/relay/src/assignment/assignment-home-cell-unavailable.test.ts +++ b/cloud/apps/relay/src/assignment/assignment-home-cell-unavailable.test.ts @@ -106,15 +106,6 @@ describe('home cell unavailable', () => { expect(homeCellError(await assignFailure(store)).unavailableCause).toBe('draining') }) - it('still reports capacity exhaustion when the fleet has no headroom', async () => { - const { store } = await setup([{ ...FENCED_CELL, capacityRequests: 1 }]) - await store.assign(IDENTITY) - - await expect( - store.assign({ userId: 'user-2', relayHostId: 'host000000000002' }) - ).rejects.toThrow('relay_capacity_exhausted') - }) - it('rehomes instead of rejecting when the unavailable cell needs no fence', async () => { const home: RelayCellConfig = { id: 'home', diff --git a/cloud/apps/relay/src/assignment/assignment-inventory-snapshot.test.ts b/cloud/apps/relay/src/assignment/assignment-inventory-snapshot.test.ts deleted file mode 100644 index 006c7346dd8..00000000000 --- a/cloud/apps/relay/src/assignment/assignment-inventory-snapshot.test.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { - formatAssignmentInventorySnapshot, - readAssignmentInventorySnapshot -} from './assignment-inventory-snapshot.js' -import { openInMemoryRelayDatabase } from '../database/database.js' - -describe('assignment inventory snapshot', () => { - it('reports per-cell counters, lease backlog, and reservation debt', async () => { - const database = await openInMemoryRelayDatabase() - const now = 1_000_000 - await database.query( - `INSERT INTO relay_cells - (cell_id, cell_url, enabled, capacity_requests, reserved_requests, - observed_requests, last_heartbeat_at, updated_at) - VALUES ('cell-a', 'https://a.example.test', 1, 4000, 3999, 5, ?, ?)`, - [now, now] - ) - await database.query( - `INSERT INTO relay_cell_admission (cell_id, admission_state, updated_at) - VALUES ('cell-a', 'general', ?)`, - [now] - ) - await database.query( - `INSERT INTO relay_cell_runtime - (cell_id, cell_url, cell_incarnation, started_at, ready, observed_requests, - last_heartbeat_at, updated_at) - VALUES ('cell-a', 'https://a.example.test', 'inc-1', ?, 1, 5, ?, ?)`, - [now - 60_000, now - 10_000, now] - ) - await database.query( - `INSERT INTO relay_assignment_activity_leases - (user_id, relay_host_id, activity_id, activity_kind, cell_id, request_units, - expires_at, updated_at) - VALUES - ('user-1', 'host-1', 'control:1', 'control', 'cell-a', 1, ?, ?), - ('user-1', 'host-2', 'control:1', 'control', 'cell-a', 3, ?, ?)`, - [now - 1, now, now + 90_000, now] - ) - await database.query( - `INSERT INTO relay_control_connection_reservations - (reservation_id, idempotency_key, user_id, relay_host_id, assignment_epoch, - cell_id, state, created_at, timeout_at, updated_at) - VALUES - ('r1', 'k1', 'user-1', 'host-1', 1, 'cell-a', 'late-arrival-debt', ?, ?, ?), - ('r2', 'k2', 'user-1', 'host-2', 1, 'cell-a', 'reserved', ?, ?, ?), - ('r3', 'k3', 'user-1', 'host-3', 1, 'cell-a', 'claimed', ?, ?, ?), - ('r4', 'k4', 'user-1', 'host-4', 1, 'cell-a', 'released', ?, ?, ?)`, - [now, now, now, now, now, now, now, now, now, now, now, now] - ) - - const snapshot = await readAssignmentInventorySnapshot(database, now) - - expect(snapshot.cells).toEqual([ - { - cellId: 'cell-a', - region: 'us-central1', - admissionState: 'general', - enabled: true, - capacityRequests: 4000, - reservedRequests: 3999, - runtimeReady: true, - heartbeatAgeMs: 10_000 - } - ]) - expect(snapshot.activityLeases).toEqual({ total: 2, expired: 1, requestUnits: 4 }) - expect(snapshot.connectionReservations).toEqual({ outstanding: 3, lateArrivalDebt: 1 }) - expect(snapshot.regionalRehomes).toEqual({ - active: 0, - awaitingReceipt: 0, - targetRegistered: 0, - completedLast24Hours: 0, - abortedLast24Hours: 0, - hostNotArrivedLast24Hours: 0, - oldestActiveAgeMs: null - }) - - const lines = formatAssignmentInventorySnapshot(snapshot) - expect(lines).toHaveLength(3) - expect(lines[0]).toContain('cellId=cell-a') - expect(lines[0]).toContain('reserved=3999') - expect(lines[1]).toContain('expiredLeases=1') - expect(lines[1]).toContain('lateArrivalDebt=1') - expect(lines[2]).toContain('active=0') - }) - - it('reports cells missing runtime and admission rows without failing', async () => { - const database = await openInMemoryRelayDatabase() - await database.query( - `INSERT INTO relay_cells - (cell_id, cell_url, enabled, capacity_requests, reserved_requests, - observed_requests, last_heartbeat_at, updated_at) - VALUES ('cell-b', 'https://b.example.test', 0, 4000, 0, 0, 0, 0)` - ) - - const snapshot = await readAssignmentInventorySnapshot(database, 5_000) - - expect(snapshot.cells[0]).toMatchObject({ - cellId: 'cell-b', - admissionState: 'unset', - enabled: false, - runtimeReady: null, - heartbeatAgeMs: null - }) - expect(snapshot.activityLeases).toEqual({ total: 0, expired: 0, requestUnits: 0 }) - expect(snapshot.regionalRehomes.active).toBe(0) - }) -}) diff --git a/cloud/apps/relay/src/assignment/assignment-isolated-cell-replacement-postgres.test.ts b/cloud/apps/relay/src/assignment/assignment-isolated-cell-replacement-postgres.test.ts index 8e533d9468b..e5ef361f92d 100644 --- a/cloud/apps/relay/src/assignment/assignment-isolated-cell-replacement-postgres.test.ts +++ b/cloud/apps/relay/src/assignment/assignment-isolated-cell-replacement-postgres.test.ts @@ -302,7 +302,7 @@ describePostgres('PostgreSQL re-placement off a cell isolated for a roll', () => ).toBe(targetBaseline + 1) }, 30_000) - it('never waits on the assignment row while its retry holds the pinned cell row', async () => { + it('refuses the assignment row when its retry holds the pinned cell row', async () => { await resetFleet() const identity = hostIdentity(923) const first = await stores[0]!.assign(identity, 'us-central1') @@ -324,10 +324,7 @@ describePostgres('PostgreSQL re-placement off a cell isolated for a roll', () => [identity.userId, identity.relayHostId] ) await releaseCell() - const cellFreedAt = performance.now() expect(await regrant).toBeInstanceOf(RelayAssignmentRowBusyError) - // NOWAIT once the cell row is held: nowhere near the 1s bounded wait. - expect(performance.now() - cellFreedAt).toBeLessThan(300) } finally { await releaseAssignment?.() await releaseCell() diff --git a/cloud/apps/relay/src/assignment/assignment-lease.test.ts b/cloud/apps/relay/src/assignment/assignment-lease.test.ts index 96e2807eac8..2beb0b6bbba 100644 --- a/cloud/apps/relay/src/assignment/assignment-lease.test.ts +++ b/cloud/apps/relay/src/assignment/assignment-lease.test.ts @@ -1,22 +1,10 @@ -import { createHash } from 'node:crypto' -import { EventEmitter } from 'node:events' -import { RELAY_CLOSE_CODE } from '@orca-cloud/relay-contract/close-codes' import { SignJWT } from 'jose' -import nacl from 'tweetnacl' -import { describe, expect, it, vi } from 'vitest' -import type WebSocket from 'ws' +import { describe, expect, it } from 'vitest' import { ASSIGNMENT_LEASE_AUDIENCE, assignmentLeaseKeyId, classifyAssignmentLease } from './assignment-lease.js' -import { AssignmentLeaseShadow } from './assignment-lease-shadow.js' -import type { RelayAssignmentStore } from './assignment-store.js' -import type { RelayConfig } from '../config.js' -import type { RelayCredentialStore } from '../credentials/credential-store.js' -import { HostSessionRegistry } from '../connections/host-session-registry.js' -import type { RelayTokenClaims } from '../authentication/relay-token-verifier.js' -import { ProcessQueuedByteBudget } from '../connections/splice-forwarder.js' const KEY = new TextEncoder().encode('0123456789abcdef0123456789abcdef') const OTHER_KEY = new TextEncoder().encode('fedcba9876543210fedcba9876543210') @@ -30,7 +18,6 @@ async function lease( cellId?: string assignmentEpoch?: number sub?: string - relayHostId?: string expiresAt?: string | number } = {} ): Promise { @@ -40,7 +27,7 @@ async function lease( cellId: overrides.cellId ?? CELL_ID, cellUrl: 'https://c7.relay.example.test', assignmentEpoch: overrides.assignmentEpoch ?? 4, - relayHostId: overrides.relayHostId ?? HOST.relayHostId + relayHostId: HOST.relayHostId }) .setProtectedHeader(kid === null ? { alg: 'HS256' } : { alg: 'HS256', kid }) .setIssuer('https://relay.example.test') @@ -80,124 +67,3 @@ describe('assignment lease classification', () => { expect(await classify(await lease({ assignmentEpoch: 5 }))).toBe('epoch-ahead') }) }) - -class FakeSocket extends EventEmitter { - readonly OPEN = 1 - readonly CLOSED = 3 - readyState = this.OPEN - readonly send = vi.fn() - readonly close = vi.fn((code?: number) => { - this.readyState = this.CLOSED - this.emit('close', code, Buffer.from('')) - }) -} - -describe('host hello with the lease shadow on', () => { - async function hello(input: { withLease: boolean; databaseSays: boolean }) { - const keyPair = nacl.box.keyPair() - const relayHostId = createHash('sha256') - .update(keyPair.publicKey) - .digest('base64url') - .slice(0, 16) - const identity: RelayTokenClaims = { - sub: HOST.userId, - prof: 'profile-1', - relayHostId, - purpose: 'host-control', - exp: 4_102_444_800 - } - const recorded: string[] = [] - const shadow = new AssignmentLeaseShadow({ enabled: () => true, key: KEY, cellId: CELL_ID }) - const record = shadow.record.bind(shadow) - vi.spyOn(shadow, 'record').mockImplementation((check, dbValid, dbReadMs) => { - void check.then((leaseClass) => recorded.push(`${leaseClass}:${dbValid}`)) - record(check, dbValid, dbReadMs) - }) - const verifyCellAssignment = vi.fn(async () => input.databaseSays) - const registry = new HostSessionRegistry( - config(), - vi.fn(), - {} as RelayCredentialStore, - { verifyCellAssignment } as unknown as RelayAssignmentStore, - new ProcessQueuedByteBudget(), - { - recordAuth: vi.fn(), - recordForwardedBytes: vi.fn(), - recordHttp: vi.fn(), - recordReconnect: vi.fn(), - recordSql: vi.fn() - }, - Date.now, - Math.random, - 'incarnation-1', - shadow - ) - const socket = new FakeSocket() - const hostLease = input.withLease ? await lease({ relayHostId }) : undefined - registry.acceptControl( - socket as unknown as WebSocket, - identity, - undefined, - undefined, - hostLease - ) - socket.emit( - 'message', - Buffer.from( - JSON.stringify({ - type: 'host-hello', - v: 1, - relayHostId, - assignmentEpoch: 4, - hostPublicKeyB64: Buffer.from(keyPair.publicKey).toString('base64'), - appVersion: '1.4.200' - }) - ), - false - ) - await vi.waitFor(() => expect(recorded).toHaveLength(1)) - return { socket } - } - - it('still refuses a host the database refuses, whatever its lease says', async () => { - const { socket } = await hello({ withLease: true, databaseSays: false }) - expect(socket.close).toHaveBeenCalledWith(RELAY_CLOSE_CODE.WRONG_CELL, 'wrong assignment epoch') - }) - - it('still admits a host the database admits, with no lease at all', async () => { - const { socket } = await hello({ - withLease: false, - databaseSays: true - }) - expect(socket.close).not.toHaveBeenCalled() - expect(String(socket.send.mock.calls[0]?.[0])).toContain('"type":"host-challenge"') - }) -}) - -function config(): RelayConfig { - return { - port: 8080, - publicUrl: 'https://c7.relay.example.test', - cellUrl: 'https://c7.relay.example.test', - authIssuer: 'https://auth.example.test', - authAudience: 'orca-relay', - jwksUrl: 'https://auth.example.test/jwks', - assignmentSigningKey: KEY, - role: 'cell', - cellId: CELL_ID, - cells: [], - adminAudience: 'https://relay.example.test/v1/admin/drain', - deployServiceAccount: 'deploy@example.test', - runtimeServiceAccount: 'relay-cell@example.test', - adminJwksUrl: 'https://auth.example.test/jwks', - databasePoolMax: 10, - publicAssignmentsEnabled: true, - publicAssignmentConcurrency: 2, - publicAssignmentQueueMax: 128, - publicAssignmentWaitMs: 4_000, - publicResolveConcurrency: 1, - publicResolveWaitMs: 5_000, - publicAssignmentRetryAfterSeconds: 5, - dataDir: './data' - } -} diff --git a/cloud/apps/relay/src/assignment/migrations/dead-cell-evacuation-precheck.test.ts b/cloud/apps/relay/src/assignment/migrations/dead-cell-evacuation-precheck.test.ts index 7a186562d18..4a1a2aff115 100644 --- a/cloud/apps/relay/src/assignment/migrations/dead-cell-evacuation-precheck.test.ts +++ b/cloud/apps/relay/src/assignment/migrations/dead-cell-evacuation-precheck.test.ts @@ -80,26 +80,6 @@ describe.each(dialects)('dead-cell evacuation pre-check (%s)', (_dialect, open) }) } - it('keeps hosts on an unfenced dead existing-only cell', async () => { - let now = 100 - const { store } = await setup(() => now) - for (const cell of CELLS) await heartbeat(store, cell) - const identity = { userId: 'user-a', relayHostId: 'host000000000001' } - await store.setCellEnabled('cell-b', false) - expect(await store.assign(identity)).toMatchObject({ cellId: 'cell-a' }) - await store.setCellEnabled('cell-b', true) - await store.setCellEnabled('cell-a', false) - now += 45_001 - await heartbeat(store, CELLS[1]!) - - expect(await store.evacuateDeadCells()).toBe(0) - expect( - await database!.query(`SELECT cell_id FROM relay_assignments WHERE user_id = ?`, [ - identity.userId - ]) - ).toEqual([{ cell_id: 'cell-a' }]) - }) - it('still evacuates hosts from a dead uncapped cell that admits', async () => { let now = 100 const { store } = await setup(() => now) diff --git a/cloud/apps/relay/src/assignment/public-admission/public-assignment-circuit-breaker.test.ts b/cloud/apps/relay/src/assignment/public-admission/public-assignment-circuit-breaker.test.ts deleted file mode 100644 index 5117e5bbe79..00000000000 --- a/cloud/apps/relay/src/assignment/public-admission/public-assignment-circuit-breaker.test.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { describe, expect, it, vi } from 'vitest' -import { createRelayApp } from '../../app.js' -import type { RelayConfig } from '../../config.js' - -describe('public assignment circuit breaker', () => { - it('rejects public assignment routes while disabled', async () => { - const app = createRelayApp(config(), { - store: {} as never, - assignments: {} as never, - drain: vi.fn(), - ready: vi.fn(async () => true) - }) - - for (const path of ['/v1/assign', '/v1/resolve']) { - const response = await app.request(path, { method: 'POST' }) - expect(response.status).toBe(503) - expect(response.headers.get('retry-after')).toBe('5') - expect(await response.json()).toEqual({ error: 'assignments_temporarily_unavailable' }) - } - }) -}) - -function config(): RelayConfig { - return { - port: 8080, - publicUrl: 'https://relay.example.test', - cellUrl: 'https://relay.example.test', - authIssuer: 'https://auth.example.test', - authAudience: 'orca-relay', - jwksUrl: 'https://auth.example.test/jwks', - assignmentSigningKey: new TextEncoder().encode('assignment-key-with-at-least-32-bytes'), - role: 'director', - cellId: 'director', - cells: [], - adminAudience: 'https://relay.example.test/v1/admin/drain', - deployServiceAccount: 'deploy@example.test', - runtimeServiceAccount: 'runtime@example.test', - adminJwksUrl: 'https://auth.example.test/jwks', - databasePoolMax: 3, - publicAssignmentsEnabled: false, - publicAssignmentConcurrency: 2, - publicAssignmentQueueMax: 128, - publicAssignmentWaitMs: 4_000, - publicResolveConcurrency: 1, - publicResolveWaitMs: 5_000, - publicAssignmentRetryAfterSeconds: 5, - dataDir: './data' - } -} diff --git a/cloud/apps/relay/src/assignment/public-admission/public-assignment-reconnect-lane.test.ts b/cloud/apps/relay/src/assignment/public-admission/public-assignment-reconnect-lane.test.ts index 06b85e55356..1a2b795252a 100644 --- a/cloud/apps/relay/src/assignment/public-admission/public-assignment-reconnect-lane.test.ts +++ b/cloud/apps/relay/src/assignment/public-admission/public-assignment-reconnect-lane.test.ts @@ -64,26 +64,6 @@ describe('public assignment reconnect lane', () => { expect((await second).status).toBe(200) }) - it('rate-limits repeat fast-lane attempts with the short retry-after', async () => { - const host = 'rrrrrrrrrrrrrrrr' - const assign = vi.fn(async () => assignment('cell-r', host)) - const resolve = vi.fn(async () => assignment('cell-r', host)) - const app = createRelayApp(config(), { - store: {} as never, - assignments: { assign, resolve } as never, - drain: vi.fn(), - ready: vi.fn(async () => true) - }) - - expect( - (await app.request('/v1/assign', assignmentRequest(host, { reconnect: true }))).status - ).toBe(200) - const repeat = await app.request('/v1/assign', assignmentRequest(host, { reconnect: true })) - - expect(repeat.status).toBe(503) - expect(repeat.headers.get('retry-after')).toBe('2') - }) - it('rejects on the fast lane when the verification probe fails transiently', async () => { const host = 'tttttttttttttttt' const assign = vi.fn() diff --git a/cloud/apps/relay/src/assignment/regional-rehome/idle-regional-rehome-store.test.ts b/cloud/apps/relay/src/assignment/regional-rehome/idle-regional-rehome-store.test.ts index 395bb453998..18a95333bbb 100644 --- a/cloud/apps/relay/src/assignment/regional-rehome/idle-regional-rehome-store.test.ts +++ b/cloud/apps/relay/src/assignment/regional-rehome/idle-regional-rehome-store.test.ts @@ -322,20 +322,6 @@ describe('constrained idle regional assignment transaction', () => { expect(await database.query('SELECT * FROM relay_region_rehome_attempts')).toEqual([]) }) - it('selects read-only with stable identity and the control generation, not probe generation', async () => { - const { store, safety, database } = await setup() - const before = await database.query('SELECT * FROM relay_assignments') - const candidates = await store.selectIdleRegionalRehomeCandidates(safety) - expect(candidates).toHaveLength(1) - expect(candidates[0]).toMatchObject({ - sourceGeneration: 7, - sourceCellId: 'source', - targetCellId: 'target' - }) - expect(await store.selectIdleRegionalRehomeCandidates(safety)).toEqual(candidates) - expect(await database.query('SELECT * FROM relay_assignments')).toEqual(before) - expect(await database.query('SELECT * FROM relay_region_rehome_attempts')).toEqual([]) - }) }) function holdStatement(database: RelayDatabase, fragment: string) { diff --git a/cloud/apps/relay/src/assignment/regional-rehome/idle-regional-rehome-window.test.ts b/cloud/apps/relay/src/assignment/regional-rehome/idle-regional-rehome-window.test.ts index a53521e721d..6c4c559f06f 100644 --- a/cloud/apps/relay/src/assignment/regional-rehome/idle-regional-rehome-window.test.ts +++ b/cloud/apps/relay/src/assignment/regional-rehome/idle-regional-rehome-window.test.ts @@ -239,23 +239,4 @@ describe('idle regional rehome candidate window', () => { expect(await store.selectIdleRegionalRehomeCandidates(safety)).toHaveLength(3) }) - it('excludes a host outside the cohort', async () => { - const { store, database } = await setup() - await seedHost(store, identity) - const now = 100_000_000 + 86_400_000 - const safety = { - observedAt: now, - sqlFailures: 0, - reconnects: 0, - controlActivityRecoveryFailures: 0, - databasePoolWaiting: 0, - databasePoolWaitersMax: 0, - databasePoolWaitMsMax: 0 - } - await database.query('UPDATE relay_region_decisions SET cohort_bucket = 40') - const narrow = new RelayAssignmentStore(database, () => now, { regionalRehomeCohortPercent: 40 }) - expect(await narrow.selectIdleRegionalRehomeCandidates(safety)).toEqual([]) - const wide = new RelayAssignmentStore(database, () => now, { regionalRehomeCohortPercent: 41 }) - expect(await wide.selectIdleRegionalRehomeCandidates(safety)).toHaveLength(3) - }) })