Closed wknd closed 7 months ago
Wallaby's worker mechanism is a little different to jest
and so our automatic configuration does not (and cannot) apply the jest setting you are using.
Jest internally has two default maxWorkers for running your tests, a watch mode default and a non-watch mode default. Wallaby combines these two concepts with initial
and regular
settings so that you get the best of both worlds, a fast startup time (Wallaby is usually faster to do a full test run than jest) and an incremental run, which assigns less worker processes to keep your system responsive.
You will need to explicitly configure the workers setting in Wallaby. You can do this in a configuration file, or in your package.json
file. Please refer to our workers docs here and here for how to create a configuration file / specify in your package.json
.
Please note, you may also use the workers.restart
property to restart processes for each run; I think this will fix the memory problem.
Issue description or question
Wallaby.js does not take jest maxworkers into account which can cause it to use an unacceptable amount of ram and CPU load. This is especially bad on machines with a lot of CPU cores.
It is made worse by jest having some sort of memory leak which may or may not finally be resolved when using node 21.
proof of concept
I made a repo with the minimum to reproduce the problem, that will run 240000 simple identical tests to illustrate the problem. https://github.com/wknd/jest-wallaby-poc
Run it with node 18 to reproduce the problem.
https://github.com/wknd/jest-wallaby-poc
setup
baseline test:
problematic test: in vscode do a
Wallaby.js: Start
Keep an eye on your CPU load during the tests.
expected result
about 20% of your cpu cores are used while running the test with wallaby. ram usage goes up.
actual result
100% of your cpu cores are used while running the test with wallaby. ram usage goes up even more than when running it jest directly. (5GB+ on my home machine with 16 threads)
when is this a problem
Since every test runner can in some cases take up multiple gigabytes of ram, this results in wallaby using up all available ram on a machine (and getting killed) on computers with many cores.
In my case I have 24 cores available on my work machine and it was encountered in an angular monorepo where running tests on the main app through wallaby would eventually bring ram usage to over the 64GB I have available.
Obviously that is a more extreme situation, but one that's way easier to fix if I can use wallaby with maxworkers.
Wallaby diagnostics report