diff --git a/src/node/heart.ts b/src/node/heart.ts index fa4835c24..b78f4edb8 100644 --- a/src/node/heart.ts +++ b/src/node/heart.ts @@ -9,9 +9,9 @@ export class Heart { private heartbeatTimer?: NodeJS.Timeout private heartbeatInterval = 60000 public lastHeartbeat = 0 - private readonly _onChange = new Emitter<"alive" | "idle" | "unknown">() + private readonly _onChange = new Emitter<"alive" | "expired" | "unknown">() readonly onChange = this._onChange.event - private state: "alive" | "idle" | "unknown" = "idle" + private state: "alive" | "expired" | "unknown" = "expired" public constructor( private readonly heartbeatPath: string, @@ -54,7 +54,7 @@ export class Heart { if (await this.isActive()) { this.beat() } else { - this.setState("idle") + this.setState("expired") } } catch (error: unknown) { logger.warn((error as Error).message) diff --git a/src/node/main.ts b/src/node/main.ts index 5846b7661..c2d3bd578 100644 --- a/src/node/main.ts +++ b/src/node/main.ts @@ -182,7 +182,7 @@ export const runCodeServer = async ( heart.onChange((state) => { clearTimeout(idleShutdownTimer) - if (state === "idle") { + if (state === "expired") { startIdleShutdownTimer() } }) diff --git a/test/unit/node/heart.test.ts b/test/unit/node/heart.test.ts index 0af7cb9fb..7ad0d2175 100644 --- a/test/unit/node/heart.test.ts +++ b/test/unit/node/heart.test.ts @@ -147,7 +147,7 @@ describe("stateChange", () => { expect(mockOnChange.mock.calls[0][0]).toBe("alive") }) - it.only("should change to idle when not active", async () => { + it.only("should change to expired when not active", async () => { jest.useFakeTimers() heart = new Heart(`${testDir}/shutdown.txt`, () => new Promise((resolve) => resolve(false))) const mockOnChange = jest.fn() @@ -155,7 +155,7 @@ describe("stateChange", () => { await heart.beat() await jest.advanceTimersByTime(60 * 1000) - expect(mockOnChange.mock.calls[1][0]).toBe("idle") + expect(mockOnChange.mock.calls[1][0]).toBe("expired") jest.clearAllTimers() jest.useRealTimers() })