2023-10-27 10:34:30 -04:00
|
|
|
import { assertEquals } from "../../../../test_util/std/assert/mod.ts";
|
2023-04-28 10:48:00 -04:00
|
|
|
import { deferred } from "../../../../test_util/std/async/deferred.ts";
|
2022-01-06 11:41:16 -05:00
|
|
|
|
|
|
|
const errorDeferred = deferred();
|
|
|
|
const closeDeferred = deferred();
|
|
|
|
|
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) => {
|
|
|
|
assertEquals((e as ErrorEvent).message, "No response from ping frame.");
|
|
|
|
errorDeferred.resolve();
|
|
|
|
};
|
|
|
|
socket.onclose = (e) => {
|
|
|
|
assertEquals(e.reason, "No response from ping frame.");
|
|
|
|
closeDeferred.resolve();
|
|
|
|
};
|
|
|
|
await respondWith(response);
|
|
|
|
|
|
|
|
await errorDeferred;
|
|
|
|
await closeDeferred;
|
|
|
|
listener.close();
|