Skip to content

Commit

Permalink
test(ext/node): reduce race condition in test case (#27207)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Dec 4, 2024
1 parent 8cd257d commit 32b4c37
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions tests/unit_node/http_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,7 @@ Deno.test("[node/http] client closing a streaming request doesn't terminate serv
let interval: number;
let uploadedData = "";
let requestError: Error | null = null;
const deferred1 = Promise.withResolvers<void>();
const server = http.createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" });
interval = setInterval(() => {
Expand All @@ -1382,13 +1383,13 @@ Deno.test("[node/http] client closing a streaming request doesn't terminate serv
clearInterval(interval);
});
req.on("error", (err) => {
deferred1.resolve();
requestError = err;
clearInterval(interval);
res.end();
});
});

const deferred1 = Promise.withResolvers<void>();
server.listen(0, () => {
// deno-lint-ignore no-explicit-any
const port = (server.address() as any).port;
Expand Down Expand Up @@ -1418,9 +1419,6 @@ Deno.test("[node/http] client closing a streaming request doesn't terminate serv

if (sentChunks >= 3) {
client.destroy();
setTimeout(() => {
deferred1.resolve();
}, 40);
} else {
setTimeout(writeChunk, 10);
}
Expand Down

0 comments on commit 32b4c37

Please sign in to comment.