Description
Today, when I run the tests using zig test
/ zig build test
, tests inside a single translation unit are being run sequentially:
Line 145 in 629f0d2
I'd love to see the tests being run in parallel.
There are two motivations here:
Directly, I have 14 cores on the laptop I use, and it'd be nice to use all of them when working on well-tested codebases.
More importantly, indirectly defaults shape testing culture. It's very easy to writhe the first three test such that they are order dependent and can't be run in parallel. And this isn't a problem at three tests. However, once you get to 3 000 tests, this becomes a problem, but at that point fixing the tests requires a lot of effort.
In other words, "my tests can't be run in parallel" is a boiling frog kind of problem, and it would help if the language helped to avert this problem before it becomes big, hence "parallel by default". As a case study, Rust went for parallel tests, and, imo, it had lasting positive effects on the ecosystem.
Of course, some software is fundamentally single threaded and it's important to avoid pessimizing this case, but Zig already have single-threaded builds just for that.
One really hard problem here is what to do with test output (logging or direct use of stderr
). If you run a bunch of tests in parallel, and something gets printing to stderr, how do you know which test is responsible? As far as I know, this problem isn't really solvable, and, to get test output, the tests should be run sequentially.