[][src]Attribute Macro ntest_timeout::timeout

#[timeout]

The timeout attribute can be used for tests to let them fail if they exceed a certain execution time. With the #[timeout] attribute a timeout in milliseconds is added to a test.

The function input must be of type int. For example #[timeout(10)] will fail if the test takes longer than 10 milliseconds.

Examples

This example will not panic

This example is not tested
#[test]
#[timeout(100)]
fn no_timeout() {
    let fifty_millis = time::Duration::from_millis(50);
    thread::sleep(fifty_millis);
}

This example will panic.

This example is not tested
#[test]
#[timeout(10)]
#[should_panic]
fn timeout() {
    let fifty_millis = time::Duration::from_millis(50);
    thread::sleep(fifty_millis);
}