Skip to content

Tests in static_any_map.rs are not atomic, may cause spurious failure. #1

Open
@kennytm

Description

@kennytm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions