2024-02-13 11:22:49 -05:00
|
|
|
import { assertEquals } from "../../../tests/util/std/assert/mod.ts";
|
2022-01-06 11:41:16 -05:00
|
|
|
|
2023-11-22 06:11:20 -05:00
|
|
|
const errorDeferred = Promise.withResolvers<void>();
|
|
|
|
const closeDeferred = Promise.withResolvers<void>();
|
2022-01-06 11:41:16 -05:00
|
|
|
|
2022-02-16 10:51:32 -05:00
|
|
|
const listener = Deno.listen({ port: 4509 });
|
2022-01-06 11:41:16 -05:00
|
|
|
console.log("READY");
|
|
|
|
const httpConn = Deno.serveHttp(await listener.accept());
|
|
|
|
const { request, respondWith } = (await httpConn.nextRequest())!;
|
|
|
|
const { response, socket } = Deno.upgradeWebSocket(request, {
|
|
|
|
idleTimeout: 1,
|
|
|
|
});
|
|
|
|
socket.onerror = (e) => {
|
2024-02-28 17:12:21 -05:00
|
|
|
console.log(e);
|
2022-01-06 11:41:16 -05:00
|
|
|
assertEquals((e as ErrorEvent).message, "No response from ping frame.");
|
|
|
|
errorDeferred.resolve();
|
|
|
|
};
|
|
|
|
socket.onclose = (e) => {
|
2024-02-28 17:12:21 -05:00
|
|
|
console.log(e);
|
2022-01-06 11:41:16 -05:00
|
|
|
assertEquals(e.reason, "No response from ping frame.");
|
|
|
|
closeDeferred.resolve();
|
|
|
|
};
|
|
|
|
await respondWith(response);
|
|
|
|
|
2023-11-22 06:11:20 -05:00
|
|
|
await errorDeferred.promise;
|
|
|
|
await closeDeferred.promise;
|
2024-02-28 17:12:21 -05:00
|
|
|
|
|
|
|
// TODO(mmastrac): this doesn't exit on its own. Why?
|
|
|
|
Deno.exit(123);
|