mirror of
https://github.com/cdr/code-server.git
synced 2025-12-07 17:02:27 +01:00
Update idle state to expired
This commit is contained in:
parent
cecb83018f
commit
bbbd6edc6a
3 changed files with 6 additions and 6 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ export const runCodeServer = async (
|
|||
|
||||
heart.onChange((state) => {
|
||||
clearTimeout(idleShutdownTimer)
|
||||
if (state === "idle") {
|
||||
if (state === "expired") {
|
||||
startIdleShutdownTimer()
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue