Skip to content
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

Fix/jest memory leaks #20

Merged
merged 11 commits into from Nov 28, 2021
Merged

Fix/jest memory leaks #20

merged 11 commits into from Nov 28, 2021

Conversation

jpb06
Copy link
Owner

@jpb06 jpb06 commented Nov 14, 2021

Huge leaking Issue with backend tests right there :

 PASS  src/modules/books/book/books.spec.ts (7.415 s, 208 MB heap size)
 PASS  src/modules/books/author/authors.spec.ts (265 MB heap size)
 PASS  src/modules/books/categories/categories.spec.ts (259 MB heap size)
 PASS  src/modules/books/book/books.service.test.ts (299 MB heap size)
 PASS  src/modules/books/categories/categories.service.test.ts (335 MB heap size)
 PASS  src/modules/books/author/authors.service.test.ts (355 MB heap size)
 PASS  src/modules/users/user/users.spec.ts (315 MB heap size)
 PASS  src/modules/users/auth/auth.service.test.ts (344 MB heap size)
 PASS  src/filters/fk-exception.filter.test.ts (366 MB heap size)
 PASS  src/modules/books/book/books.controller.test.ts (410 MB heap size)
 PASS  src/filters/fk-deletion-exception.filter.test.ts (420 MB heap size)
 PASS  src/modules/users/user/users.controller.test.ts (458 MB heap size)
 PASS  src/modules/users/auth/strategies/local.strategy.test.ts (362 MB heap size)
 PASS  src/pipes/validation.pipe.test.ts (385 MB heap size)
 PASS  src/modules/database/database.service.test.ts (419 MB heap size)
 PASS  src/bootstrap.test.ts (471 MB heap size)
 PASS  src/modules/users/user/users.service.test.ts (503 MB heap size)
 PASS  src/pipes/number-array.pipe.test.ts (513 MB heap size)
 PASS  src/main.test.ts (548 MB heap size)

ts-jest

kulshekhar/ts-jest#1967

 PASS  src/modules/books/book/books.spec.ts (5.07 s, 126 MB heap size)
 PASS  src/modules/books/author/authors.spec.ts (175 MB heap size)
 PASS  src/modules/books/categories/categories.spec.ts (232 MB heap size)
 PASS  src/modules/books/book/books.service.test.ts (161 MB heap size)
 PASS  src/modules/books/categories/categories.service.test.ts (183 MB heap size)
 PASS  src/modules/books/author/authors.service.test.ts (204 MB heap size)
 PASS  src/modules/users/user/users.spec.ts (241 MB heap size)
 PASS  src/modules/users/auth/auth.service.test.ts (268 MB heap size)
 PASS  src/filters/fk-exception.filter.test.ts (287 MB heap size)
 PASS  src/modules/books/book/books.controller.test.ts (322 MB heap size)
 PASS  src/filters/fk-deletion-exception.filter.test.ts (340 MB heap size)
 PASS  src/modules/users/user/users.controller.test.ts (363 MB heap size)
 PASS  src/modules/users/auth/strategies/local.strategy.test.ts (389 MB heap size)
 PASS  src/pipes/validation.pipe.test.ts (412 MB heap size)
 PASS  src/modules/database/database.service.test.ts (285 MB heap size)
 PASS  src/bootstrap.test.ts (341 MB heap size)
 PASS  src/modules/users/user/users.service.test.ts (364 MB heap size)
 PASS  src/pipes/number-array.pipe.test.ts (373 MB heap size)
 PASS  src/main.test.ts (358 MB heap size)

node > v16.10

jestjs/jest#11956

Switching to v16.10.0 helps a lot (from v16.13.0) :

 PASS  src/modules/books/book/books.spec.ts (119 MB heap size)
 PASS  src/modules/books/author/authors.spec.ts (159 MB heap size)
 PASS  src/modules/books/categories/categories.spec.ts (193 MB heap size)
 PASS  src/modules/books/book/books.service.test.ts (206 MB heap size)
 PASS  src/modules/books/categories/categories.service.test.ts (217 MB heap size)
 PASS  src/modules/books/author/authors.service.test.ts (126 MB heap size)
 PASS  src/modules/users/user/users.spec.ts (145 MB heap size)
 PASS  src/modules/users/auth/auth.service.test.ts (125 MB heap size)
 PASS  src/filters/fk-exception.filter.test.ts (139 MB heap size)
 PASS  src/modules/books/book/books.controller.test.ts (173 MB heap size)
 PASS  src/filters/fk-deletion-exception.filter.test.ts (172 MB heap size)
 PASS  src/modules/users/user/users.controller.test.ts (193 MB heap size)
 PASS  src/modules/users/auth/strategies/local.strategy.test.ts (143 MB heap size)
 PASS  src/pipes/validation.pipe.test.ts (149 MB heap size)
 PASS  src/modules/database/database.service.test.ts (175 MB heap size)
 PASS  src/bootstrap.test.ts (203 MB heap size)
 PASS  src/modules/users/user/users.service.test.ts (147 MB heap size)
 PASS  src/pipes/number-array.pipe.test.ts (154 MB heap size)
 PASS  src/main.test.ts (183 MB heap size)

What did NOT help:

  • add an afterEach/afterAll to close/flushlogs and garbage collect the INestApplication instance
  • explicit garbage collector calls in afterAll
  • moving prisma artifacts outside of node_modules
  • moving deepmocks inside tests

@jpb06 jpb06 marked this pull request as draft November 14, 2021 21:54
@jpb06 jpb06 marked this pull request as ready for review November 28, 2021 18:47
@sonarcloud
Copy link

sonarcloud bot commented Nov 28, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@jpb06 jpb06 merged commit f88e84b into master Nov 28, 2021
@jpb06 jpb06 deleted the fix/jest-memory-leaks branch November 28, 2021 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant