idle-kill.integration.test.ts30 lines · main
1// Integration test for CLAUDE.md §7.3 — isolates idle longer than
2// `idleKillMs` get retired by the sweeper. The next invocation must
3// cold-start a fresh process (different PID). We use the test-only
4// `triggerIdleCheck()` hook on `IsolatePoolImpl` to drive the sweeper
5// deterministically rather than wait for the 30s production interval.
6
7import { describe, expect, test } from 'bun:test';
8
9import { runIdleKillFixture } from './test-helpers.js';
10
11describe('idle kill (integration)', () => {
12 test('isolate killed after idleKillMs elapses; next invoke cold-starts', async () => {
13 const { firstPid, secondPid, cleanup } = await runIdleKillFixture({
14 fnName: 'v',
15 deploymentId: 'd1',
16 idleKillMs: 100, // tiny idle threshold
17 fnSource: `
18 import { query } from '@briven/cli/server';
19 export const v = query(async () => 'ok');
20 `,
21 });
22 try {
23 expect(firstPid).toBeGreaterThan(0);
24 expect(secondPid).toBeGreaterThan(0);
25 expect(firstPid).not.toBe(secondPid);
26 } finally {
27 await cleanup();
28 }
29 }, 30_000);
30});