From 3bae68eda659aebd1eb16fb470cfadead4d9512a Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 6 Dec 2024 00:25:16 +0900 Subject: [PATCH] test(ext/node): fix flaky node/http2.createServer() test (#27208) --- tests/unit_node/http2_test.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/unit_node/http2_test.ts b/tests/unit_node/http2_test.ts index c540c90f7e..90f2388124 100644 --- a/tests/unit_node/http2_test.ts +++ b/tests/unit_node/http2_test.ts @@ -152,6 +152,7 @@ Deno.test("[node/http2.createServer()]", { // TODO(satyarohith): enable the test on windows. ignore: Deno.build.os === "windows", }, async () => { + const serverListening = Promise.withResolvers(); const server = http2.createServer((_req, res) => { res.setHeader("Content-Type", "text/html"); res.setHeader("X-Foo", "bar"); @@ -159,8 +160,10 @@ Deno.test("[node/http2.createServer()]", { res.write("Hello, World!"); res.end(); }); - server.listen(0); - const port = (server.address() as net.AddressInfo).port; + server.listen(0, () => { + serverListening.resolve((server.address() as net.AddressInfo).port); + }); + const port = await serverListening.promise; const endpoint = `http://localhost:${port}`; const response = await curlRequest([