Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Jest - memory leak #9000

Closed
ghost opened this issue Oct 2, 2019 · 2 comments
Closed

Jest - memory leak #9000

ghost opened this issue Oct 2, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented Oct 2, 2019

🐛 Bug Report

Hi everyone,

we have some little issue with memory leak in test runner.
This causes little problems in our Project. I found a similar bug report
#8816 but it's still open.
Thanks a lot for your advices.

$ npm run test:debug get.applications

PASS tests/cases/api/get.applications12.test.ts (107 MB heap size)
PASS tests/cases/api/get.applications9.test.ts (106 MB heap size)
...
PASS tests/cases/api/get.applications17.test.ts (113 MB heap size)
PASS tests/cases/api/get.applications23.test.ts (113 MB heap size)

Test Suites: 40 passed, 40 total
Tests: 200 passed, 200 total
Snapshots: 0 total
Time: 16.51s
Ran all test suites matching /get.applications/i.

When I run testing with the -detectLeaks parameter, I get an error. Yes, I know this is just an experimental feature, but it will tell you something.

$ npm run test:detectLeaks get.applications1.test

FAIL tests/cases/api/get.applications1.test.ts
● Test suite failed to run

EXPERIMENTAL FEATURE!
Your test suite is leaking memory. Please ensure all references are cleaned.

There is a number of things that can leak memory:
  - Async operations that have not finished (e.g. fs.readFile).
  - Timers not properly mocked (e.g. setInterval, setTimeout).
  - Keeping references to the global scope.

  at node_modules/@jest/core/build/TestScheduler.js:257:24
  at asyncGeneratorStep (node_modules/@jest/core/build/TestScheduler.js:131:24)
  at _next (node_modules/@jest/core/build/TestScheduler.js:151:9)
  at node_modules/@jest/core/build/TestScheduler.js:156:7
  at node_modules/@jest/core/build/TestScheduler.js:148:12
  at onResult (node_modules/@jest/core/build/TestScheduler.js:271:25)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 4.016s
Ran all test suites matching /get.applications1.test/i.

To Reproduce

I've created a repository with 40 same test file:
https://github.com/FilipMucka/memory-leak

If you want reproduce first 'PASS' scenario with show heap size run:

$ npm run test:debug get.applications

and if you want 'FAIL' scenario run:

$ npm run test:detectLeaks get.applications1.test

Expected behaviour

Memory usage for each test will be the same.

Link to repl or repo (highly encouraged)

https://github.com/FilipMucka/memory-leak

envinfo

System:
OS: macOS Mojave 10.14.6
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Binaries:
Node: 10.16.3 - /usr/local/bin/node
npm: 6.9.0 - /usr/local/bin/npm
npmPackages:
jest: 24.9.0 => 24.9.0

@thymikee
Copy link
Collaborator

thymikee commented Oct 2, 2019

You spawn a http server without closing it down after the test finish. It's a leak in user's code, not in Jest.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

1 participant