Skip to content

Commit bbbd6ed

Browse files
Update idle state to expired
1 parent cecb830 commit bbbd6ed

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/node/heart.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ export class Heart {
99
private heartbeatTimer?: NodeJS.Timeout
1010
private heartbeatInterval = 60000
1111
public lastHeartbeat = 0
12-
private readonly _onChange = new Emitter<"alive" | "idle" | "unknown">()
12+
private readonly _onChange = new Emitter<"alive" | "expired" | "unknown">()
1313
readonly onChange = this._onChange.event
14-
private state: "alive" | "idle" | "unknown" = "idle"
14+
private state: "alive" | "expired" | "unknown" = "expired"
1515

1616
public constructor(
1717
private readonly heartbeatPath: string,
@@ -54,7 +54,7 @@ export class Heart {
5454
if (await this.isActive()) {
5555
this.beat()
5656
} else {
57-
this.setState("idle")
57+
this.setState("expired")
5858
}
5959
} catch (error: unknown) {
6060
logger.warn((error as Error).message)

src/node/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export const runCodeServer = async (
182182

183183
heart.onChange((state) => {
184184
clearTimeout(idleShutdownTimer)
185-
if (state === "idle") {
185+
if (state === "expired") {
186186
startIdleShutdownTimer()
187187
}
188188
})

test/unit/node/heart.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ describe("stateChange", () => {
147147

148148
expect(mockOnChange.mock.calls[0][0]).toBe("alive")
149149
})
150-
it.only("should change to idle when not active", async () => {
150+
it.only("should change to expired when not active", async () => {
151151
jest.useFakeTimers()
152152
heart = new Heart(`${testDir}/shutdown.txt`, () => new Promise((resolve) => resolve(false)))
153153
const mockOnChange = jest.fn()
154154
heart.onChange(mockOnChange)
155155
await heart.beat()
156156

157157
await jest.advanceTimersByTime(60 * 1000)
158-
expect(mockOnChange.mock.calls[1][0]).toBe("idle")
158+
expect(mockOnChange.mock.calls[1][0]).toBe("expired")
159159
jest.clearAllTimers()
160160
jest.useRealTimers()
161161
})

0 commit comments

Comments
 (0)