1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-11 01:58:05 -05:00

reduce formatting diff

This commit is contained in:
Yoshiya Hinosawa 2024-10-17 23:44:40 +09:00
parent bd16624612
commit 2e017a8b78
No known key found for this signature in database
GPG key ID: 9017DB4559488785

View file

@ -1651,17 +1651,14 @@ Deno.test("[node/http] In ClientRequest, option.hostname has precedence over opt
await responseReceived.promise; await responseReceived.promise;
}); });
Deno.test( const IGNORED_Y =
"[node/http] upgraded socket closes when the server closed without closing handshake", "[node/http] upgraded socket closes when the server closed without closing handshake";
{ Deno.test(IGNORED_Y, { ignore: true }, async () => {
ignore: true, const clientSocketClosed = Promise.withResolvers<void>();
}, const serverProcessClosed = Promise.withResolvers<void>();
async () => {
const clientSocketClosed = Promise.withResolvers<void>();
const serverProcessClosed = Promise.withResolvers<void>();
// Uses the server in different process to shutdown it without closing handshake // Uses the server in different process to shutdown it without closing handshake
const server = ` const server = `
Deno.serve({ port: 1337 }, (req) => { Deno.serve({ port: 1337 }, (req) => {
if (req.headers.get("upgrade") != "websocket") { if (req.headers.get("upgrade") != "websocket") {
return new Response("ok"); return new Response("ok");
@ -1676,50 +1673,49 @@ Deno.test(
}); });
`; `;
const p = new Deno.Command("deno", { args: ["eval", server] }).spawn(); const p = new Deno.Command("deno", { args: ["eval", server] }).spawn();
// Wait for the server to respond // Wait for the server to respond
await retry(async () => { await retry(async () => {
const resp = await fetch("http://localhost:1337"); const resp = await fetch("http://localhost:1337");
const _text = await resp.text(); const _text = await resp.text();
});
const options = {
port: 1337,
host: "127.0.0.1",
headers: {
"Connection": "Upgrade",
"Upgrade": "websocket",
"Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ==",
},
};
http.request(options).on("upgrade", (_res, socket) => {
socket.on("close", () => {
console.log("client socket closed");
clientSocketClosed.resolve();
}); });
socket.on("data", async (data) => {
// receives pong message
assertEquals(data, Buffer.from("8104706f6e67", "hex"));
const options = { p.kill();
port: 1337, await p.status;
host: "127.0.0.1",
headers: {
"Connection": "Upgrade",
"Upgrade": "websocket",
"Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ==",
},
};
http.request(options).on("upgrade", (_res, socket) => { console.log("process closed");
socket.on("close", () => { serverProcessClosed.resolve();
console.log("client socket closed");
clientSocketClosed.resolve();
});
socket.on("data", async (data) => {
// receives pong message
assertEquals(data, Buffer.from("8104706f6e67", "hex"));
p.kill(); // sending some additional message
await p.status;
console.log("process closed");
serverProcessClosed.resolve();
// sending some additional message
socket.write(Buffer.from("81847de88e01", "hex"));
socket.write(Buffer.from("0d81e066", "hex"));
});
// sending ping message
socket.write(Buffer.from("81847de88e01", "hex")); socket.write(Buffer.from("81847de88e01", "hex"));
socket.write(Buffer.from("0d81e066", "hex")); socket.write(Buffer.from("0d81e066", "hex"));
}).end(); });
await clientSocketClosed.promise; // sending ping message
await serverProcessClosed.promise; socket.write(Buffer.from("81847de88e01", "hex"));
}, socket.write(Buffer.from("0d81e066", "hex"));
); }).end();
await clientSocketClosed.promise;
await serverProcessClosed.promise;
});