|
| 1 | +import * as httpserver from "./httpserver" |
| 2 | +import * as integration from "./integration" |
| 3 | + |
| 4 | +describe("health", () => { |
| 5 | + let codeServer: httpserver.HttpServer | undefined |
| 6 | + |
| 7 | + afterEach(async () => { |
| 8 | + if (codeServer) { |
| 9 | + await codeServer.close() |
| 10 | + codeServer = undefined |
| 11 | + } |
| 12 | + }) |
| 13 | + |
| 14 | + it("/healthz", async () => { |
| 15 | + ;[, , codeServer] = await integration.setup(["--auth=none"], "") |
| 16 | + const resp = await codeServer.fetch("/healthz") |
| 17 | + expect(resp.status).toBe(200) |
| 18 | + const json = await resp.json() |
| 19 | + expect(json).toStrictEqual({ lastHeartbeat: 0, status: "expired" }) |
| 20 | + }) |
| 21 | + |
| 22 | + it("/healthz (websocket)", async () => { |
| 23 | + ;[, , codeServer] = await integration.setup(["--auth=none"], "") |
| 24 | + const ws = codeServer.ws("/healthz") |
| 25 | + const message = await new Promise((resolve, reject) => { |
| 26 | + ws.on("error", console.error) |
| 27 | + ws.on("message", (message) => { |
| 28 | + try { |
| 29 | + const j = JSON.parse(message.toString()) |
| 30 | + resolve(j) |
| 31 | + } catch (error) { |
| 32 | + reject(error) |
| 33 | + } |
| 34 | + }) |
| 35 | + ws.on("open", () => ws.send(JSON.stringify({ event: "health" }))) |
| 36 | + }) |
| 37 | + ws.terminate() |
| 38 | + expect(message).toStrictEqual({ event: "health", status: "expired", lastHeartbeat: 0 }) |
| 39 | + }) |
| 40 | +}) |
0 commit comments