Fix hanging yarn test:e2e by adding proper connection lifecycle management#27
Merged
Merged
Conversation
…hanging e2e tests - MongoModule: split into MONGO_CLIENT + MONGODB providers; add MongoClientService implementing OnApplicationShutdown to close the MongoClient on teardown - RedisModule: add RedisCleanupService implementing OnApplicationShutdown to disconnect the ioredis client on teardown - WebSocketChatGateway: implement OnApplicationShutdown to disconnect its private ioredis client on teardown - test/app.e2e-spec.ts: switch beforeEach → beforeAll and add afterAll that calls app.close(), triggering the shutdown lifecycle - CI: remove --forceExit from yarn test:e2e
Copilot created this pull request from a session on behalf of
runephilosof-abtion
July 2, 2026 07:48
View session
runephilosof-abtion
marked this pull request as ready for review
July 2, 2026 07:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jest was hanging indefinitely after e2e tests because MongoDB and Redis connections were never closed — the event loop stayed alive waiting for them.
--forceExitwas masking the root cause.Changes
test/app.e2e-spec.tsbeforeEach→beforeAll; addedafterAll(() => app.close())to trigger the NestJS shutdown lifecyclesrc/common/mongo/mongo.module.tsMONGO_CLIENTprovider (returns theMongoClient) andMONGODBderived from itMongoClientService implements OnApplicationShutdown→client.close()MongoClientreference was lost inside the factory, making cleanup impossiblesrc/common/redis/redis.module.tsRedisCleanupService implements OnApplicationShutdown→client.disconnect()src/knowledgebase/websocketchat.gateway.tsWebSocketChatGatewaycreates its own privateRedisclient; implementsOnApplicationShutdownto disconnect it.github/workflows/package-tests.yml--forceExitPattern used
NestJS calls
onApplicationShutdownon all providers whenapp.close()is invoked, which is now guaranteed by theafterAllteardown.