Skip to content

Commit

Permalink
Fix open handles in tests (#4858)
Browse files Browse the repository at this point in the history
## About the changes
This fixes a bunch of openHandles from our tests

I've used this script to find out the ones that leave them:
`find src -name "*.test.ts" -printf "%f\n" | xargs -i sh -c "echo =====
{} && yarn test {}"`

If there's an issue, the script will halt and the last filename will be
the one that has to be fixed.

Each commit fixes one problem so it's easy to review
  • Loading branch information
gastonfournier committed Sep 28, 2023
1 parent f9c3259 commit 93da4a1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/test/e2e/api/admin/favorites.e2e.test.ts
Expand Up @@ -102,6 +102,7 @@ beforeAll(async () => {

afterAll(async () => {
await app.destroy();
await db.destroy();
});

afterEach(async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/api/admin/public-signup-token.e2e.test.ts
Expand Up @@ -7,7 +7,7 @@ import { PublicSignupTokenCreateSchema } from '../../../../lib/openapi/spec/publ
let stores;
let db;

beforeEach(async () => {
beforeAll(async () => {
db = await dbInit('test', getLogger);
stores = db.stores;
});
Expand Down
1 change: 1 addition & 0 deletions src/test/e2e/api/admin/user/pat.e2e.test.ts
Expand Up @@ -31,6 +31,7 @@ beforeAll(async () => {
afterAll(async () => {
getLogger.setMuteError(false);
await app.destroy();
await db.destroy();
});

test('should create a PAT', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e/api/auth/simple-password-provider.e2e.test.ts
Expand Up @@ -61,7 +61,7 @@ beforeEach(async () => {
});
});

afterAll(async () => {
afterEach(async () => {
await app.destroy();
await db.destroy();
});
Expand Down
4 changes: 4 additions & 0 deletions src/test/e2e/custom-auth.test.ts
Expand Up @@ -21,6 +21,10 @@ beforeAll(async () => {
stores = db.stores;
});

afterAll(async () => {
await db.destroy();
});

test('Using custom auth type without defining custom middleware causes default DENY ALL policy to take effect', async () => {
jest.spyOn(global.console, 'error').mockImplementation(() => jest.fn());
const { request, destroy } = await setupAppWithCustomAuth(
Expand Down
12 changes: 8 additions & 4 deletions src/test/e2e/helpers/test-helper.ts
Expand Up @@ -216,10 +216,14 @@ async function createApp(
const request = supertest.agent(app);

const destroy = async () => {
services.versionService.destroy();
services.clientInstanceService.destroy();
services.clientMetricsServiceV2.destroy();
services.proxyService.destroy();
// iterate on the keys of services and if the services at that key has a function called destroy then call it
await Promise.all(
Object.keys(services).map(async (key) => {
if (services[key].destroy) {
await services[key].destroy();
}
}),
);
};

// TODO: use create from server-impl instead?
Expand Down

0 comments on commit 93da4a1

Please sign in to comment.