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

Memory Leak on using Jest Circus as the Test-Runner #19

Closed
sauravhiremath opened this issue Jul 1, 2020 · 4 comments
Closed

Memory Leak on using Jest Circus as the Test-Runner #19

sauravhiremath opened this issue Jul 1, 2020 · 4 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@sauravhiremath
Copy link
Member

Where did the memory leak originate?

mem-leak

How to reproduce the issue?

// Checkout PR 18
git fetch origin pull/18/head:individual-test-report

// Clean your yarn builds and re-build again
yarn clean-all
yarn

//Run this to reproduce the issue
JEST_CIRCUS=1 yarn test-leak

How does the "memory leak test fail" look?

    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 onResult (packages/jest-core/build/TestScheduler.js:190:18)
          at Array.map (<anonymous>)
@sauravhiremath sauravhiremath added bug Something isn't working help wanted Extra attention is needed labels Jul 1, 2020
@kunal-kushwaha
Copy link
Member

Reference: #6

@SimenB
Copy link
Collaborator

SimenB commented Jul 2, 2020

I won't have time to look into this properly until the weekend/next week, but jest-circus has always failed the test-leak script up until jestjs#9934 landed a couple of months ago. So I'd try to make sure you're rebased on top of master, and then try to do a bisect of all the commits on top of that.

@sauravhiremath
Copy link
Member Author

This is a rough draft of how I traced the mem-leak. Will edit it later for a cleaner one

TestCaseReporterHandler.ts [sendMessageToJest(‘test-case-result’, testCaseResult)] -> TestRunner -> EventEmiiter.on(‘test-case-result’, (testCaseResult)) ->TestScheduler (onTestCaseResult) -> ReporterDispatcher (onTestCaseResult) -> default_reporter (onTestCaseResult) -> Status (addTestCaseResult())

Here, TestCaseReporterHandler emits test-case-result, but here it passes down the array reference and not a copy of array. Hence in all the flow mentioned above, the reference still persists causing testCaseResult to be present globally for all workers spawned.

This was avoided down the lane, in Status function by making a deepCyclicCopy of the array passed. Hence removing the global reference of the array once and for all, that too for all spawned workers

@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 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants