Git Product home page Git Product logo

Comments (3)

karpikpl avatar karpikpl commented on August 25, 2024 1

So I have good news and bad news.
Good news is that the test is passing with mocha but failing with jest.

Same test, just different testing framework:

const Leakage =  require('leakage');
var assert = require('assert');

describe('leaks', function() {

    let expected, actual;

    beforeEach(function() {
        expected = 0;
        actual = 0;
    });

    afterEach(function() {
        if (!expected || expected == actual) return;
          var err = new Error('expected ' + expected + ' assertions, got ' + actual);
          this.currentTest.emit('error', err);
    });

    it('leak test', function() {
        this.timeout(100000);
        expected = 181;

         return Leakage.iterate.async(async () => {
            let dummyPromise = new Promise((resolve) => {
               setTimeout(() => resolve('ok'), 1);
            });

            try {
                const result = await dummyPromise;
                assert.equal(result, 'ok');
                actual++;
            } catch (e) {
                throw 'this should not happen ' + e;
            }
        });
    })
});

With mocha it passes and it's also much faster - 5s.

With Jest it fails but it's also much slower

$ jest --runInBand
 FAIL  tests/test.js (26.959s)
  ● leak test

    MemoryLeakError: Heap grew on 6 subsequent garbage collections (180 of 180 iterations) by 362 kB.

      Iterations between GCs: 30

      Final GC details:
      [   30.3 kB] [+ 378x] [-   2x] system / Context
      [   23.4 kB] [+ 378x] [-   1x] Closure
      [   21.9 kB] [+ 103x] [-   4x] Array
      [    3.6 kB] [+  31x] [-   1x] Timeout
      ... (9 more)

      at testConstantHeapSize (node_modules/leakage/lib/testConstantHeapSize.js:24:12)
      at Object.onAllDone (node_modules/leakage/lib/index.js:130:27)
      at Immediate.onHeapDiff (node_modules/leakage/lib/index.js:114:16)

I was unable to pass the --heap-file heap-diff.json param to jest. It worked with mocha, but mocha doesn't have the issue

from leakage.

andywer avatar andywer commented on August 25, 2024

Hey @karpikpl!

Your code looks fine so far. Haven't ever tested the lib with Jasmine, though.

Can you please post the exact error output and ideally a heap dump (maybe in a GitHub gist or so)?

from leakage.

andywer avatar andywer commented on August 25, 2024

Thanks for the comprehensive update! πŸ‘πŸ™‚

I suppose we can turn that into one actionable only: Document that you should use tape or mocha; test runners that come with a minimal overhead and donβ€˜t do much magic.

from leakage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.