I have multiple integration tests. If I run each one individually, everything works fine. If I run all simultaneously, I sometimes get errors due to each individual test taking longer (so that an integration test can end up producing more output data than expected, and thus fail assertions). A solution I'm currently using is to put #[serial] attribute on that integration test. But then it will take longer to run through all the integration tests.
tokio crate has a function called block_in_place() that lets you run a chosen sequence of lines single-threaded while letting you run everything else multi-threaded.
I'm looking for something that works similar to block_in_place() but applies the same effect as#[serial] for the chosen block of code, while letting everything else in that integration test run in parallel to the other integration tests. How to achieve this?
On option would be to have a static RwLock, and take a write guard for the critical section and a read guard in all of the places that can’t run concurrently with it.
Tokio's block_in_place is not supposed to limit parallelism.
In tokio's multi-threaded runtime, blocked tasks will be moved to other threads where possible, and run there.
In single-threaded runtime it creates a bottleneck that makes the async runtime unresponsive, but from tokio's perspective that a broken behavior, not the intended use.