-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Oak leaking async ops on simple server test #454
Comments
I should add that if I replace URL |
In this instance got a hunch it is your setup that's leaking based on the error.
E.g. the following adjustment to your test file doesn't throw: import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
const PORT = 8080;
let listenPromise: Promise<void>;
const controller = new AbortController();
// Starts server and saves the returned promise into `listenPromise`
export const startServer = function (port: number): void {
const app = new Application(),
router = new Router();
// Ping route returns "PONG""
router.get("/ping", (ctx) => {
ctx.response.body = "PONG";
ctx.response.status = 200;
});
app.use(router.routes());
app.use(router.allowedMethods());
listenPromise = app.listen({ port: port, signal: controller.signal });
};
export const stopServer = async function (): Promise<void> {
controller.abort();
await listenPromise;
};
Deno.test("test that I can connect to server", async function () {
// starts small server defined above
startServer(PORT);
const url = "http://localhost:8080/ping";
const response = await fetch(url);
const text = await response.text();
assertEquals(text, "PONG");
await stopServer();
}); There may be a way to setup the tests to avoid having the See https://github.com/oakserver/oak#opening-the-server E.g. in addition to your const listeningPromise = new Promise<void>((resolve) => {
app.addEventListener(
"listen",
() => {
resolve();
},
);
}); |
When trying to use oak to unit test some REST services, the server seems to leak async ops. Simplest code to reproduce below. Would love to know if I am doing something wrong (maybe explicit close connection?) or if this is a bug. Thanks much.
I run the test below using:
deno test -A server.test.ts
Sample code:
The console output looks like this:
The text was updated successfully, but these errors were encountered: