|
1 | 1 | import * as httpserver from "../../../utils/httpserver" |
2 | 2 | import * as integration from "../../../utils/integration" |
3 | 3 |
|
4 | | -describe("health", () => { |
5 | | - let codeServer: httpserver.HttpServer | undefined |
| 4 | +describe("health (http)", () => { |
| 5 | + let codeServer: httpserver.HttpServer | httpserver.HttpsServer | undefined |
6 | 6 |
|
7 | 7 | afterEach(async () => { |
8 | 8 | if (codeServer) { |
@@ -38,3 +38,47 @@ describe("health", () => { |
38 | 38 | expect(message).toStrictEqual({ event: "health", status: "expired", lastHeartbeat: 0 }) |
39 | 39 | }) |
40 | 40 | }) |
| 41 | + |
| 42 | +describe("health (https)", () => { |
| 43 | + let codeServer: httpserver.HttpServer | httpserver.HttpsServer | undefined |
| 44 | + |
| 45 | + afterEach(async () => { |
| 46 | + if (codeServer) { |
| 47 | + await codeServer.dispose() |
| 48 | + codeServer = undefined |
| 49 | + } |
| 50 | + }) |
| 51 | + |
| 52 | + it("/healthz (websocket) with --cert", async () => { |
| 53 | + // NOTES@jsjoeio |
| 54 | + // We connect to /healthz via a websocket |
| 55 | + // and send a message and then we expect it to work |
| 56 | + // with our HTTPS server |
| 57 | + // and the cert arg passed in as well. |
| 58 | + // Notes from Slack |
| 59 | + // Ahser said "we could connect it to /vscode |
| 60 | + // Add the appropriate query variables (it expects connectionType and some other things, probably easiest to look at the browser and see) |
| 61 | + // Then it might be enough to just see if that connection errors or not |
| 62 | + // If it does not error then you probably have to try actually sending some data on it" |
| 63 | + // Not sure what do do there. Guess I need to spin up code-server |
| 64 | + // and look at the network tab. |
| 65 | + // Also confused on the /healthz vs /vscode part |
| 66 | + // The websocket runs on /healthz. Is that it? |
| 67 | + codeServer = await integration.setup(["--auth=none", "--cert"], "") |
| 68 | + const ws = codeServer.ws("/healthz") |
| 69 | + const message = await new Promise((resolve, reject) => { |
| 70 | + ws.on("error", console.error) |
| 71 | + ws.on("message", (message) => { |
| 72 | + try { |
| 73 | + const j = JSON.parse(message.toString()) |
| 74 | + resolve(j) |
| 75 | + } catch (error) { |
| 76 | + reject(error) |
| 77 | + } |
| 78 | + }) |
| 79 | + ws.on("open", () => ws.send(JSON.stringify({ event: "health" }))) |
| 80 | + }) |
| 81 | + ws.terminate() |
| 82 | + expect(message).toStrictEqual({ event: "health", status: "expired", lastHeartbeat: 0 }) |
| 83 | + }) |
| 84 | +}) |
0 commit comments