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

Archiver seems leaking memory in Jest tests just by importing it #353

Closed
voroshkov opened this issue Nov 13, 2018 · 2 comments
Closed

Archiver seems leaking memory in Jest tests just by importing it #353

voroshkov opened this issue Nov 13, 2018 · 2 comments

Comments

@voroshkov
Copy link

voroshkov commented Nov 13, 2018

Running Jest tests on my project I noticed a constant memory consumption growth. A short investigation revealed that if I comment out the archiver import statement, memory gets released after each tests set execution.
Here's the simple setup that reproduces the issue:

There's a set of 20 test files, each having the same code:

// my_test1.e2e.js, my_test2.e2e.js ...

import archiver from 'archiver';

describe(`describe`, () => {
    // make sure to collect garbage before each test (run node with --expose-gc option)
    beforeEach(() => global.gc());
    // introducing a timeout to watch for memory growth
    test('test', async () => await new Promise(r => setTimeout(r, 3000)));
});

Jest config is as simple as:

// jest.config.e2e.js

module.exports = {
    // The test environment that will be used for testing
    testEnvironment: 'node',

    // The glob patterns Jest uses to detect test files
    testMatch: ['**/__tests__/**/my_test*.e2e.js'],
};

Run the tests with the following command (use --runInBand to make Jest run all tests subsequently in a single node process):

node --expose-gc node_modules/jest/bin/jest --config="jest.config.e2e.js" --runInBand

Result:

And here's the Node process monitoring results captured while running the tests. It clearly shows that memory allocation grows with each subsequent tests set execution:

image

And here's what I have after commenting out the import archiver from 'archiver'; statement in all test files:
image

@voroshkov
Copy link
Author

voroshkov commented Nov 13, 2018

This seems to be the issue in graceful-fs, which had been fixed 11 days ago: isaacs/node-graceful-fs#137

You just need to update the dependency in package.json

@oleksiygontariownit
Copy link

Any update on this issue?

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

No branches or pull requests

3 participants