From 32b4c37c05afb4b0458631809d1c1cdf17155251 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Wed, 4 Dec 2024 11:29:31 +0900 Subject: [PATCH] test(ext/node): reduce race condition in test case (#27207) --- tests/unit_node/http_test.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts index 31ac6bee25..048ddf30f5 100644 --- a/tests/unit_node/http_test.ts +++ b/tests/unit_node/http_test.ts @@ -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(); const server = http.createServer((req, res) => { res.writeHead(200, { "Content-Type": "text/plain" }); interval = setInterval(() => { @@ -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(); server.listen(0, () => { // deno-lint-ignore no-explicit-any 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) { client.destroy(); - setTimeout(() => { - deferred1.resolve(); - }, 40); } else { setTimeout(writeChunk, 10); }