mirror of
https://github.com/denoland/deno.git
synced 2024-11-15 16:43:44 -05:00
27 lines
824 B
TypeScript
27 lines
824 B
TypeScript
|
import { assertEquals } from "../../../test_util/std/testing/asserts.ts";
|
||
|
import { deferred } from "../../../test_util/std/async/deferred.ts";
|
||
|
|
||
|
const errorDeferred = deferred();
|
||
|
const closeDeferred = deferred();
|
||
|
|
||
|
const listener = Deno.listen({ port: 4502 });
|
||
|
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();
|