From b5b99042856cacecd46f32661e5e5c8df0128c75 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Sat, 27 Jul 2024 22:47:47 +0900 Subject: [PATCH] test(ext/node): reduce http_test flakiness (#24742) (cherry picked from commit 99e811f5eb8070cfa41272c9e630c7767cac22c2) --- tests/unit_node/http_test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts index c9a1ec3ea7..d4cf5941f4 100644 --- a/tests/unit_node/http_test.ts +++ b/tests/unit_node/http_test.ts @@ -1325,9 +1325,10 @@ Deno.test("[node/http] http.request() post streaming body works", async () => { } }); - const deferred = Promise.withResolvers(); + const responseEnded = Promise.withResolvers(); + const fileClosed = Promise.withResolvers(); const timeout = setTimeout(() => { - deferred.reject(new Error("timeout")); + responseEnded.reject(new Error("timeout")); }, 5000); server.listen(0, () => { // deno-lint-ignore no-explicit-any @@ -1359,7 +1360,7 @@ Deno.test("[node/http] http.request() post streaming body works", async () => { const response = JSON.parse(responseBody); assertEquals(res.statusCode, 200); assertEquals(response.bytes, contentLength); - deferred.resolve(); + responseEnded.resolve(); }); }); @@ -1369,8 +1370,10 @@ Deno.test("[node/http] http.request() post streaming body works", async () => { const readStream = fs.createReadStream(filePath); readStream.pipe(req); + readStream.on("close", fileClosed.resolve); }); - await deferred.promise; + await responseEnded.promise; + await fileClosed.promise; assertEquals(server.listening, true); server.close(); clearTimeout(timeout);