mirror of
https://github.com/cdr/code-server.git
synced 2025-12-08 09:23:00 +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 heartbeatTimer?: NodeJS.Timeout
|
||||||
private heartbeatInterval = 60000
|
private heartbeatInterval = 60000
|
||||||
public lastHeartbeat = 0
|
public lastHeartbeat = 0
|
||||||
private readonly _onChange = new Emitter<"alive" | "idle" | "unknown">()
|
private readonly _onChange = new Emitter<"alive" | "expired" | "unknown">()
|
||||||
readonly onChange = this._onChange.event
|
readonly onChange = this._onChange.event
|
||||||
private state: "alive" | "idle" | "unknown" = "idle"
|
private state: "alive" | "expired" | "unknown" = "expired"
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private readonly heartbeatPath: string,
|
private readonly heartbeatPath: string,
|
||||||
|
|
@ -54,7 +54,7 @@ export class Heart {
|
||||||
if (await this.isActive()) {
|
if (await this.isActive()) {
|
||||||
this.beat()
|
this.beat()
|
||||||
} else {
|
} else {
|
||||||
this.setState("idle")
|
this.setState("expired")
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
logger.warn((error as Error).message)
|
logger.warn((error as Error).message)
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,7 @@ export const runCodeServer = async (
|
||||||
|
|
||||||
heart.onChange((state) => {
|
heart.onChange((state) => {
|
||||||
clearTimeout(idleShutdownTimer)
|
clearTimeout(idleShutdownTimer)
|
||||||
if (state === "idle") {
|
if (state === "expired") {
|
||||||
startIdleShutdownTimer()
|
startIdleShutdownTimer()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ describe("stateChange", () => {
|
||||||
|
|
||||||
expect(mockOnChange.mock.calls[0][0]).toBe("alive")
|
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()
|
jest.useFakeTimers()
|
||||||
heart = new Heart(`${testDir}/shutdown.txt`, () => new Promise((resolve) => resolve(false)))
|
heart = new Heart(`${testDir}/shutdown.txt`, () => new Promise((resolve) => resolve(false)))
|
||||||
const mockOnChange = jest.fn()
|
const mockOnChange = jest.fn()
|
||||||
|
|
@ -155,7 +155,7 @@ describe("stateChange", () => {
|
||||||
await heart.beat()
|
await heart.beat()
|
||||||
|
|
||||||
await jest.advanceTimersByTime(60 * 1000)
|
await jest.advanceTimersByTime(60 * 1000)
|
||||||
expect(mockOnChange.mock.calls[1][0]).toBe("idle")
|
expect(mockOnChange.mock.calls[1][0]).toBe("expired")
|
||||||
jest.clearAllTimers()
|
jest.clearAllTimers()
|
||||||
jest.useRealTimers()
|
jest.useRealTimers()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue