Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

profiling memory leaks in karma-runner/jasmine

I have an AngularJS application with about 2000 unit tests which consume a lot of memory. Once tests launched, they run pretty fast (in Chrome) until memory consumption hits 1.5GB at which point every test starts to take about 3 seconds.

Now, I'm pretty damn sure this is not related to Why are my AngularJS, Karma / Jasmine tests running so slowly?.

At this point I have no idea if it's the tests that are leaking or the application itself. I would like to profile the test execution.

I've read unit-tests karma-runner/jasmine profiling and am trying to do the following:

You can use localhost:9876/debug.html and profile the memory. Check the memory before executing (after Jasmine executed all the describe() blocks and collected the tests) and then after executing the tests - it should be the same.

But how can this be done?

I don't really understand how it is possible to check before and after. Can I somehow pause the tests execution? Is jasmine able to tell me when it's "collected the tests" and wait for me to do the profiling?

Or is there any other approach?

like image 201
Oleg Avatar asked Dec 18 '14 13:12

Oleg


1 Answers

This is not a full answer but just "thinking out loud"...

  1. I would start isolating a suite first.
  2. Then I'd start to have a look at the Chrome Console API - so focus on one browser only for the moment .
  3. Now in each beforeEach or afterEach trigger and shutdown the profiler (using a a suite + test name for each profiling): see the console.profile(\[label\]) and console.profileEnd() calls.
  4. At this point you don't need to stop anything to run the profiling, at the end of the testing you'll have all the results (with labels).

Once found the place where the memory goes up you can focus the area and probably start debugging in a more specific way...

like image 99
MarcoL Avatar answered Oct 20 '22 19:10

MarcoL