Generally, Rust runs tests in parallel.
In https://github.com/tinco/entity_rust/blob/master/tests/static_any_map.rs, the 3 tests all operate on the same global map. Even if the map is wrapped in a SharedMutex, it is not enough to ensure thread-safety, e.g. some code in static_map_initial_set may run in the middle of static_map_multi_set, causing the test to spuriously fail.
| Thread 1 |
Thread 2 |
static_map_initial_set() |
|
|
static_map_multi_set() |
my_map::clear_all() |
|
my_map::push(&name, i) |
|
|
my_map::clear_all() |
let queue = my_map::get(&name) |
|
| Received an empty queue |
|
assert_eq!(queue.len(), 1); but queue.len() == 0 |
|
| 💥 |
|
The tests can be serialized using a mutex, see rust-lang/rust#43155.