serial_test

Function is_locked_serially

Source
pub fn is_locked_serially(name: Option<&str>) -> bool
Expand description

Check if the current thread is holding a serial lock

Can be used to assert that a piece of code can only be called from a test marked #[serial].

Example, with #[serial]:

use serial_test::{is_locked_serially, serial};

fn do_something_in_need_of_serialization() {
    assert!(is_locked_serially(None));

    // ...
}

#[test]
#[serial]
fn main() {
    do_something_in_need_of_serialization();
}

Example, missing #[serial]:

use serial_test::{is_locked_serially, serial};

#[test]
// #[serial] // <-- missing
fn main() {
    assert!(is_locked_serially(None));
}

Example, #[test(some_key)]:

use serial_test::{is_locked_serially, serial};

#[test]
#[serial(some_key)]
fn main() {
    assert!(is_locked_serially(Some("some_key")));
    assert!(!is_locked_serially(None));
}