1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-11 00:08:30 +01:00

chore: re-add max listeners (#6522)

## About the changes
Some tests are reporting this error:

`MaxListenersExceededWarning: Possible EventEmitter memory leak
detected. 11 UPDATE_REVISION listeners added to
[ConfigurationRevisionService]. Use emitter.setMaxListeners() to
increase limit`

I thought it's because of this change
https://github.com/Unleash/unleash/pull/6400#discussion_r1511494201 but
it was not.

I've managed to get a trace of the issue following this
https://stackoverflow.com/q/62897235/239613 and now we can identify
`ConfigurationRevisionService` as one explanation. The reason is that
it's a singleton that should be cleaned up after tests.

E.g.:
https://github.com/Unleash/unleash/actions/runs/8248332132/job/22558419656?pr=6517#step:8:15
This commit is contained in:
Gastón Fournier 2024-03-12 16:34:55 +01:00 committed by GitHub
parent 6278cdb6c7
commit 16507a971b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 1 deletions

View File

@ -45,7 +45,7 @@
"prebuild:watch": "yarn run clean",
"build:watch": "tsc -w --strictNullChecks false",
"prebuild": "yarn run clean",
"test": "NODE_ENV=test PORT=4243 jest",
"test": "NODE_ENV=test PORT=4243 node --trace-warnings node_modules/.bin/jest",
"test:unit": "NODE_ENV=test PORT=4243 jest --testPathIgnorePatterns=src/test/e2e --testPathIgnorePatterns=dist",
"test:docker": "./scripts/docker-postgres.sh",
"test:report": "NODE_ENV=test PORT=4243 jest --reporters=\"default\" --reporters=\"jest-junit\"",

View File

@ -78,4 +78,8 @@ export default class ConfigurationRevisionService extends EventEmitter {
return this.revisionId;
}
destroy(): void {
ConfigurationRevisionService.instance?.removeAllListeners();
}
}

View File

@ -52,6 +52,9 @@ describe('responseTimeMetrics old behavior', () => {
getAppCountSnapshot: jest.fn(),
};
const eventBus = new EventEmitter();
afterEach(() => {
eventBus.removeAllListeners();
});
test('uses baseUrl and route path to report metrics', async () => {
let timeInfo: any;