roc-streaming / roc-toolkit

Real-time audio streaming over the network.
https://roc-streaming.org
Mozilla Public License 2.0
1.02k stars 203 forks source link

Add stress tests for task queues #645

Open gavv opened 7 months ago

gavv commented 7 months ago

See #644 for introduction to tasks queues.

We have unit tests for ctl::ControlTaskQueue and pipeline::PipelineLoop, but unit tests can't detect all possible races. Since the implementation of the lock-free operations is tricky enough (especially in ctl::ControlTaskQueue), it's important to write good stress tests that are able to detect races, and periodically run them on supported architectures (at least x86_64, arm32, and arm64).

We need two stress tests: one for ctl::ControlTaskQueue and one pipeline::PipelineLoop. The first will be more complicated since ControlTaskQueue provides more operations with tasks compared to PipelineLoop.

A stress test should repeatedly schedule, re-schedule, cancel, and wait tasks from multiple threads, at random time, and with random task deadline. Task processing should also take random time.

The random delays should be selected in a way so that we periodically have both contended and uncontended cases. The test should have enough randomness to cover the following cases:

The test should ensure that the following invariants are always met: