1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-18 13:22:55 -05:00

test(ext/node): reduce race condition in test case (#27207)

This commit is contained in:
Yoshiya Hinosawa 2024-12-04 11:29:31 +09:00 committed by GitHub
parent 8cd257de3d
commit 32b4c37c05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1370,6 +1370,7 @@ Deno.test("[node/http] client closing a streaming request doesn't terminate serv
let interval: number; let interval: number;
let uploadedData = ""; let uploadedData = "";
let requestError: Error | null = null; let requestError: Error | null = null;
const deferred1 = Promise.withResolvers<void>();
const server = http.createServer((req, res) => { const server = http.createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" }); res.writeHead(200, { "Content-Type": "text/plain" });
interval = setInterval(() => { interval = setInterval(() => {
@ -1382,13 +1383,13 @@ Deno.test("[node/http] client closing a streaming request doesn't terminate serv
clearInterval(interval); clearInterval(interval);
}); });
req.on("error", (err) => { req.on("error", (err) => {
deferred1.resolve();
requestError = err; requestError = err;
clearInterval(interval); clearInterval(interval);
res.end(); res.end();
}); });
}); });
const deferred1 = Promise.withResolvers<void>();
server.listen(0, () => { server.listen(0, () => {
// deno-lint-ignore no-explicit-any // deno-lint-ignore no-explicit-any
const port = (server.address() as any).port; const port = (server.address() as any).port;
@ -1418,9 +1419,6 @@ Deno.test("[node/http] client closing a streaming request doesn't terminate serv
if (sentChunks >= 3) { if (sentChunks >= 3) {
client.destroy(); client.destroy();
setTimeout(() => {
deferred1.resolve();
}, 40);
} else { } else {
setTimeout(writeChunk, 10); setTimeout(writeChunk, 10);
} }