diff --git a/server/src/engine/lifecycle.test.ts b/server/src/engine/lifecycle.test.ts index 1f810ef..44a9263 100644 --- a/server/src/engine/lifecycle.test.ts +++ b/server/src/engine/lifecycle.test.ts @@ -504,4 +504,45 @@ describe('fight lifecycle', () => { .toBeLessThanOrEqual(expectedAWinMax) } }) + + it('fight loop throughput: >500 fights/second (no I/O)', () => { + const fights = 5000 + const start = performance.now() + + for (let f = 0; f < fights; f++) { + const eloA = 1000 + (f % 10) * 100 + const eloB = 1000 + ((f * 3) % 10) * 100 + const botA = { id: 'perf-a', name: 'PerfA' } + const botB = { id: 'perf-b', name: 'PerfB' } + const usedTypes = new Set() + let comboA = 0 + let comboB = 0 + const rounds = 7 + (f % 4) + + for (let r = 0; r < rounds; r++) { + const challenge = pickChallenge(usedTypes, null, undefined, r + 1) + usedTypes.add(challenge.type) + const respA = mockResponse(challenge, 'confident', eloA) + const respB = mockResponse(challenge, 'clueless', eloB) + const result = scoreRound( + challenge, botA, botB, + { answer: respA.answer, timeMs: respA.timeMs, timedOut: respA.timedOut, error: respA.error }, + { answer: respB.answer, timeMs: respB.timeMs, timedOut: respB.timedOut, error: respB.error }, + null, comboA, comboB, + ) + if (result.winnerId === botA.id) { comboA++; comboB = 0 } + else if (result.winnerId === botB.id) { comboB++; comboA = 0 } + } + + // Elo + tier calculation + calculateElo(eloA, eloB) + calculateTier(eloA, f % 50, f % 20) + } + + const elapsed = performance.now() - start + const fightsPerSec = Math.round(fights / (elapsed / 1000)) + + // Must process >500 fights/sec (scoring pipeline only, no I/O) + expect(fightsPerSec).toBeGreaterThan(500) + }) })