Crate repeated_assert [] [src]

An assertion macro that tries to assert expressions multiple times

repeated_assert! re-tries to assert expressions until either all expressions are true or the maximum amount of repetitions has been reached. The current thread will be blocked between tries.

repeated_assert! is useful when waiting for events from another thread (or process). Waiting for a short time might result in a failing test, while waiting too long is a waste of time.

Examples

Waiting for a file to appear (re-try up to 10 times, wait 50 ms between tries)

repeated_assert!{ 10, Duration::from_millis(50);
    if Path::new("should_appear_soon.txt").exists();
};

Waiting for variable x to equal 3

repeated_assert!{ 10, Duration::from_millis(50);
    eq x, 3;
};

Multiple assertions

repeated_assert!{ 10, Duration::from_millis(50);
    if Path::new("should_appear_soon.txt").exists();
    eq x, 3;
};

Temporary variables

repeated_assert!{ 10, Duration::from_millis(50);
    let checksum = crc("file_is_being_written.txt");
    eq checksum, 1234;
};

Macros

repeated_assert