1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00

Fix open handles in tests (#4858)

## 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
This commit is contained in:
Gastón Fournier 2023-09-28 12:13:51 +02:00 committed by GitHub
parent f9c3259083
commit 93da4a1217
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 6 deletions

View File

@ -102,6 +102,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
await app.destroy(); await app.destroy();
await db.destroy();
}); });
afterEach(async () => { afterEach(async () => {

View File

@ -7,7 +7,7 @@ import { PublicSignupTokenCreateSchema } from '../../../../lib/openapi/spec/publ
let stores; let stores;
let db; let db;
beforeEach(async () => { beforeAll(async () => {
db = await dbInit('test', getLogger); db = await dbInit('test', getLogger);
stores = db.stores; stores = db.stores;
}); });

View File

@ -31,6 +31,7 @@ beforeAll(async () => {
afterAll(async () => { afterAll(async () => {
getLogger.setMuteError(false); getLogger.setMuteError(false);
await app.destroy(); await app.destroy();
await db.destroy();
}); });
test('should create a PAT', async () => { test('should create a PAT', async () => {

View File

@ -61,7 +61,7 @@ beforeEach(async () => {
}); });
}); });
afterAll(async () => { afterEach(async () => {
await app.destroy(); await app.destroy();
await db.destroy(); await db.destroy();
}); });

View File

@ -21,6 +21,10 @@ beforeAll(async () => {
stores = db.stores; 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 () => { 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()); jest.spyOn(global.console, 'error').mockImplementation(() => jest.fn());
const { request, destroy } = await setupAppWithCustomAuth( const { request, destroy } = await setupAppWithCustomAuth(

View File

@ -216,10 +216,14 @@ async function createApp(
const request = supertest.agent(app); const request = supertest.agent(app);
const destroy = async () => { const destroy = async () => {
services.versionService.destroy(); // iterate on the keys of services and if the services at that key has a function called destroy then call it
services.clientInstanceService.destroy(); await Promise.all(
services.clientMetricsServiceV2.destroy(); Object.keys(services).map(async (key) => {
services.proxyService.destroy(); if (services[key].destroy) {
await services[key].destroy();
}
}),
);
}; };
// TODO: use create from server-impl instead? // TODO: use create from server-impl instead?