diff options
author | Bert Belder <bertbelder@gmail.com> | 2020-05-14 06:49:45 +0200 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2020-05-14 14:14:35 +0200 |
commit | 676be6632c113b61d95e9a0897c4810d63e479b2 (patch) | |
tree | 7ce382af69e34a3c6bab78ef69cf4c831af20a01 | |
parent | c474d383543708fc636c06dd2e4a9100495f45c5 (diff) |
Fix flakiness in std file_server tests (#5306)
Fixes: #5275
-rw-r--r-- | std/http/file_server_test.ts | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/std/http/file_server_test.ts b/std/http/file_server_test.ts index 07c8618c1..2ff114906 100644 --- a/std/http/file_server_test.ts +++ b/std/http/file_server_test.ts @@ -28,9 +28,16 @@ async function startFileServer(): Promise<void> { assert(s !== null && s.includes("server listening")); } -function killFileServer(): void { +async function killFileServer(): Promise<void> { 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<void> => { @@ -46,7 +53,7 @@ test("file_server serveFile", async (): Promise<void> => { ); assertEquals(downloadedFile, localFile); } finally { - killFileServer(); + await killFileServer(); } }); @@ -68,7 +75,7 @@ test("serveDirectory", async function (): Promise<void> { assert(/<td class="mode">(\s)*\(unknown mode\)(\s)*<\/td>/.test(page)); assert(page.includes(`<a href="/README.md">README.md</a>`)); } finally { - killFileServer(); + await killFileServer(); } }); @@ -81,7 +88,7 @@ test("serveFallback", async function (): Promise<void> { assertEquals(res.status, 404); const _ = await res.text(); } finally { - killFileServer(); + await killFileServer(); } }); @@ -99,7 +106,7 @@ test("serveWithUnorthodoxFilename", async function (): Promise<void> { assertEquals(res.status, 200); _ = await res.text(); } finally { - killFileServer(); + await killFileServer(); } }); |