1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00
denoland-deno/tests/testdata/run/websocket_server_idletimeout.ts
Asher Gomez f248050cb4
chore: use @std prefix for internal module specifiers (#24543)
This change aims to replace all relative import specifiers targeted at
`tests/util/std` with mapped ones (using a `deno.json` file). Towards
updating the `std` git submodule.
2024-07-25 10:26:54 +10:00

29 lines
875 B
TypeScript

import { assertEquals } from "@std/assert/mod.ts";
const errorDeferred = Promise.withResolvers<void>();
const closeDeferred = Promise.withResolvers<void>();
const listener = Deno.listen({ port: 4509 });
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) => {
console.log(e);
assertEquals((e as ErrorEvent).message, "No response from ping frame.");
errorDeferred.resolve();
};
socket.onclose = (e) => {
console.log(e);
assertEquals(e.reason, "No response from ping frame.");
closeDeferred.resolve();
};
await respondWith(response);
await errorDeferred.promise;
await closeDeferred.promise;
// TODO(mmastrac): this doesn't exit on its own. Why?
Deno.exit(123);