From 676be6632c113b61d95e9a0897c4810d63e479b2 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Thu, 14 May 2020 06:49:45 +0200 Subject: [PATCH] Fix flakiness in std file_server tests (#5306) Fixes: #5275 --- std/http/file_server_test.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/std/http/file_server_test.ts b/std/http/file_server_test.ts index 07c8618c11..2ff1149064 100644 --- a/std/http/file_server_test.ts +++ b/std/http/file_server_test.ts @@ -28,9 +28,16 @@ async function startFileServer(): Promise { assert(s !== null && s.includes("server listening")); } -function killFileServer(): void { +async function killFileServer(): Promise { fileServer.close(); - fileServer.stdout?.close(); + // Process.close() kills the file server process. However this termination + // happens asynchronously, and since we've just closed the process resource, + // we can't use `await fileServer.status()` to wait for the process to have + // exited. As a workaround, wait for its stdout to close instead. + // TODO(piscisaureus): when `Process.kill()` is stable and works on Windows, + // switch to calling `kill()` followed by `await fileServer.status()`. + await Deno.readAll(fileServer.stdout!); + fileServer.stdout!.close(); } test("file_server serveFile", async (): Promise => { @@ -46,7 +53,7 @@ test("file_server serveFile", async (): Promise => { ); assertEquals(downloadedFile, localFile); } finally { - killFileServer(); + await killFileServer(); } }); @@ -68,7 +75,7 @@ test("serveDirectory", async function (): Promise { assert(/(\s)*\(unknown mode\)(\s)*<\/td>/.test(page)); assert(page.includes(`README.md`)); } finally { - killFileServer(); + await killFileServer(); } }); @@ -81,7 +88,7 @@ test("serveFallback", async function (): Promise { assertEquals(res.status, 404); const _ = await res.text(); } finally { - killFileServer(); + await killFileServer(); } }); @@ -99,7 +106,7 @@ test("serveWithUnorthodoxFilename", async function (): Promise { assertEquals(res.status, 200); _ = await res.text(); } finally { - killFileServer(); + await killFileServer(); } });