tests: Speed up the cancellable test
The test added for #1841 (closed) spawned 100000 threads. That was fine on a desktop machine, but on a heavily loaded CI machine, it could result in large (and unpredictable) slowdowns, resulting in the test taking over 120s in about 1 in 5 runs, and hence failing that CI pipeline due to a timeout. When passing normally on CI, the test would take around 90s.
Here’s a histogram of time per iteration on a failing (timed out) test run. Each iteration is one thread spawn:
Iteration duration (µs) | Frequency ------------------------+---------- ≤100 | 0 100–200 | 30257 200–400 | 13696 400–800 | 1046 800–1000 | 123 1000–2000 | 583 2000–4000 | 3779 4000–8000 | 4972 8000–10000 | 1027 10000–20000 | 2610 20000–40000 | 650 40000–80000 | 86 80000–100000 | 10 100000–200000 | 2 >200000 | 0
There’s no actual need for the test to spawn 100000 threads, so rewrite it to reuse a single thread, and pass new data to that thread.
Reverting the original commit (e4a690f5) reproduces the failure on 100 out of 100 test runs with this commit applied, so the test still works.
The test now takes 3s, rather than 11s, to run on my computer, and has
passed when run with meson test --repeat 1000 cancellable
.
Signed-off-by: Philip Withnall withnall@endlessm.com