summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--std/http/file_server_test.ts19
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();
}
});