ut
ut copied to clipboard
Parallel test runner is not actually parallel
Expected Behavior
The example for the parallel test runner uses std::for_each(std::execution::par, ...)
to demonstrate running several test suites in parallel. I expect the tests to actually run in separate threads.
Actual Behavior
In practice on my machine, this isn't actually executed in parallel. As proof: GDB shows no thread being created, and std::this_thread::get_id()
is the same in both suites.
If I force the suites to run in separate threads with
std::thread t1([&]() { suites_[0](); });
std::thread t2([&]() { suites_[1](); });
t1.join();
t2.join();
the console output is interleaving results from both threads. To make this more obvious, I have edited some of assertions to fail in each suite. As you can see, the output is not readable:
test.1.1
test.2.1
test.2.2
test.1.2
test.2.3
test.1.3
Running "test.1
"test.2.1"...1
parallel_runner.cpp:64:FAILED [
"test.1.2"...2 == 1]parallel_runner.cpp:55:FAILED [2 == 1]
FAILED
Running "test.2.3"...PASSED
Running "test.1.3"...PASSED
===============================================================================
tests: 3 | 1 failed
asserts: 6 | 4 passed | 2 failed
.
Steps to Reproduce the Problem
- Edit the
parallel_runner.cpp
example to insertstd::cout << "thread ID: " << std::this_thread::get_id() << std::endl;
in each test suite. - Compile and run.
- Thread IDs are the same.
Specifications
- Version: 1.1.9
- Platform: Linux x64 (Ubuntu 22.04)
- Subsystem: g++ 11.4