0

I am running jestjs unit tests with several ten/hundred thousands of data (pass in as array to test.each()), and it hits heap out of memory.

google online and have try: NODE_OPTIONS='--max-old-space-size=8192' jest --detectOpenHandles --logHeapUsage

but the test like stuck at 1 test suite for overnight, checking at os level, memory 100%, disk 100%, but CPU 4% only. I am guessing it was not enough memory and pause??

The program unit being test is pretty simple, create an object , do some calculation and return result. so I guess, the memory use for previous tests didn't get free up?

thank you very much!

  • I'm not familiar with NodeJS, but I cannot conceive that they would implement it so that you would need to "force" a garbage collection. I suspect that your application has memory leaks, and *that* is why it is using so much memory. Alternatively, it just needs too much RAM ... compared with what is available. (The symptoms sound like "thrashing" which is what happens when you are trying to use too much virtual memory ... and the OS is madly swapping pages backwards and forwards between RAM and disk.) – Stephen C Jun 25 '22 at 01:48
  • Can you show relevant code so we can see more detail about what you're doing? If you are in a synchronous loop which never pauses and never returns control back to the event loop and creates millions of objects, then indeed you may not be giving the garbage collector any cycles to run. But, it would help if we could see exactly what you are actually doing because it may not be a GC issue at all - it could be a memory use issue if the memory is technically still being "used" and thus not eligible for garbage collection. – jfriend00 Jun 25 '22 at 03:01

0 Answers0