2021-07-28 07:52:57 +08:00
|
|
|
import * as httpserver from "../../../utils/httpserver"
|
|
|
|
import * as integration from "../../../utils/integration"
|
2021-02-17 04:14:21 +08:00
|
|
|
|
|
|
|
describe("health", () => {
|
|
|
|
let codeServer: httpserver.HttpServer | undefined
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
if (codeServer) {
|
2021-10-29 04:27:17 +08:00
|
|
|
await codeServer.dispose()
|
2021-02-17 04:14:21 +08:00
|
|
|
codeServer = undefined
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it("/healthz", async () => {
|
2021-05-06 01:20:38 +08:00
|
|
|
codeServer = await integration.setup(["--auth=none"], "")
|
2021-02-17 04:14:21 +08:00
|
|
|
const resp = await codeServer.fetch("/healthz")
|
|
|
|
expect(resp.status).toBe(200)
|
|
|
|
const json = await resp.json()
|
|
|
|
expect(json).toStrictEqual({ lastHeartbeat: 0, status: "expired" })
|
|
|
|
})
|
|
|
|
|
|
|
|
it("/healthz (websocket)", async () => {
|
2021-05-06 01:20:38 +08:00
|
|
|
codeServer = await integration.setup(["--auth=none"], "")
|
2021-02-17 04:14:21 +08:00
|
|
|
const ws = codeServer.ws("/healthz")
|
|
|
|
const message = await new Promise((resolve, reject) => {
|
2023-03-03 17:12:34 +08:00
|
|
|
ws.on("error", (err) => {
|
|
|
|
console.error("[healthz]", err)
|
|
|
|
})
|
2021-02-17 04:14:21 +08:00
|
|
|
ws.on("message", (message) => {
|
|
|
|
try {
|
|
|
|
const j = JSON.parse(message.toString())
|
|
|
|
resolve(j)
|
|
|
|
} catch (error) {
|
|
|
|
reject(error)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
ws.on("open", () => ws.send(JSON.stringify({ event: "health" })))
|
|
|
|
})
|
|
|
|
ws.terminate()
|
|
|
|
expect(message).toStrictEqual({ event: "health", status: "expired", lastHeartbeat: 0 })
|
|
|
|
})
|
|
|
|
})
|