1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 07:44:48 -05:00

Fix flakiness in std file_server tests (#5306)

Fixes: #5275
This commit is contained in:
Bert Belder 2020-05-14 06:49:45 +02:00
parent c474d38354
commit 676be6632c
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461

View file

@ -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();
}
});