From 1f8570ec344a66cd8a9531dd5dddcdfdc43bdc29 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Fri, 2 Oct 2026 15:47:47 -0700 Subject: [PATCH] Advance full shutdown deadlines in mocked Codex connection tests (#24893) --- .../codex/codex-app-server-connection.test.ts | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/main/codex/codex-app-server-connection.test.ts b/src/main/codex/codex-app-server-connection.test.ts index 3d95e7ce380..d36cfac47a4 100644 --- a/src/main/codex/codex-app-server-connection.test.ts +++ b/src/main/codex/codex-app-server-connection.test.ts @@ -475,6 +475,7 @@ describe('openCodexAppServerConnection', () => { }) it('reports unproven close when forced termination did not produce an exit event', async () => { + vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }) const { child, spawnImpl } = stubChild({ exitOnStdinEnd: false }) answerInitialize(child) const connection = await openCodexAppServerConnection( @@ -483,7 +484,22 @@ describe('openCodexAppServerConnection', () => { spawnImpl ) - await expect(connection.close()).resolves.toBe(false) + const forcedKill = new Promise((resolve) => { + child.kill.mockImplementation((signal) => { + if (signal === 'SIGKILL') { + resolve() + } + }) + }) + const closing = connection.close() + await flushStreams() + await vi.advanceTimersByTimeAsync(GRACEFUL_EXIT_MS) + await forcedKill + await vi.advanceTimersByTimeAsync(0) + await vi.advanceTimersByTimeAsync(1_000) + + await expect(closing).resolves.toBe(false) + expect(vi.getTimerCount()).toBe(0) }, 10_000) it('shares one eventual exit proof across concurrent close callers', async () => { @@ -813,6 +829,7 @@ describe('openCodexAppServerConnection', () => { }) it('keeps a graceful close quiet when stdin breaks during the reap', async () => { + vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }) const { child, spawnImpl } = stubChild({ exitOnStdinEnd: false }) answerInitialize(child) const exits: string[] = [] @@ -822,15 +839,26 @@ describe('openCodexAppServerConnection', () => { spawnImpl ) child.stdin.on('finish', () => child.stdin.emit('error', new Error('write EPIPE'))) - child.kill.mockImplementation(() => { - child.emit('exit', null, 'SIGKILL') - return true + const forcedKill = new Promise((resolve) => { + child.kill.mockImplementation((signal) => { + child.emit('exit', null, 'SIGKILL') + if (signal === 'SIGKILL') { + resolve() + } + return true + }) }) const inFlight = rejection(connection.request('turn/start')) - await connection.close() + const closing = connection.close() + await flushStreams() + await vi.advanceTimersByTimeAsync(GRACEFUL_EXIT_MS) + await forcedKill + await vi.advanceTimersByTimeAsync(0) + await expect(closing).resolves.toBe(true) expect((await inFlight).message).toContain('EPIPE') expect(exits).toHaveLength(0) + expect(vi.getTimerCount()).toBe(0) }) })