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 memory leaks in tests #2393

Closed
mkurapov opened this issue Feb 5, 2024 · 0 comments · Fixed by #2394
Closed

Fix memory leaks in tests #2393

mkurapov opened this issue Feb 5, 2024 · 0 comments · Fixed by #2394
Assignees
Labels
type: tests Testing related

Comments

@mkurapov
Copy link
Contributor

mkurapov commented Feb 5, 2024

Context

When trying to debug remaining open handles in Jest tests reviewing this PR, I was unable to run jest tests serially via --runInBand/--detectOpenHandles because they were running out of memory due to a number of possible memory leaks.

There is an experimental jest argument: --detectLeaks that will fail a test if it detects that it is leaking memory:

max ~/interledger/rafiki/packages/backend [main] $ node ../../node_modules/jest/bin/jest.js --runInBand --detectLeaks --detectOpenHandles
{"level":30,"time":1707131063083,"pid":12851,"hostname":"max.local","msg":"creating knex"}
 FAIL   backend  src/open_payments/payment/outgoing/service.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 onResult (node_modules/.pnpm/@jest+core@29.7.0/node_modules/@jest/core/build/TestScheduler.js:150:18)
      at node_modules/.pnpm/@jest+core@29.7.0/node_modules/@jest/core/build/TestScheduler.js:254:19
      at node_modules/.pnpm/emittery@0.13.1/node_modules/emittery/index.js:363:13
          at Array.map (<anonymous>)
      at Emittery.emit (node_modules/.pnpm/emittery@0.13.1/node_modules/emittery/index.js:361:23)

 FAIL   backend  src/open_payments/payment/combined/service.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 onResult (node_modules/.pnpm/@jest+core@29.7.0/node_modules/@jest/core/build/TestScheduler.js:150:18)
      at node_modules/.pnpm/@jest+core@29.7.0/node_modules/@jest/core/build/TestScheduler.js:254:19
      at node_modules/.pnpm/emittery@0.13.1/node_modules/emittery/index.js:363:13
          at Array.map (<anonymous>)
      at Emittery.emit (node_modules/.pnpm/emittery@0.13.1/node_modules/emittery/index.js:361:23)
      
      
.... and so on      

This fails most of our tests due to several reasons.

It looks like the main culprit is the nock library:

Some other culprits are the

@mkurapov mkurapov added the type: tests Testing related label Feb 5, 2024
@mkurapov mkurapov self-assigned this Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: tests Testing related
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant