Attribute Macro serial_test::serial

source · []
#[serial]
Expand description

Allows for the creation of serialised Rust tests

#[test]
#[serial]
fn test_serial_one() {
  // Do things
}

#[test]
#[serial]
fn test_serial_another() {
  // Do things
}

Multiple tests with the serial attribute are guaranteed to be executed in serial. Ordering of the tests is not guaranteed however. If you have other tests that can be run in parallel, but would clash if run at the same time as the serial tests, you can use the parallel attribute.

If you want different subsets of tests to be serialised with each other, but not depend on other subsets, you can add an argument to serial, and all calls with identical arguments will be called in serial. e.g.

#[test]
#[serial(something)]
fn test_serial_one() {
  // Do things
}

#[test]
#[serial(something)]
fn test_serial_another() {
  // Do things
}

#[test]
#[serial(other)]
fn test_serial_third() {
  // Do things
}

#[test]
#[serial(other)]
fn test_serial_fourth() {
  // Do things
}

test_serial_one and test_serial_another will be executed in serial, as will test_serial_third and test_serial_fourth but neither sequence will be blocked by the other

For each test, a timeout can be specified with the timeout_ms parameter to the serial attribute. Note that the timeout is counted from the first invocation of the test, not from the time the previous test was completed. This can lead to some unpredictable behavior based on the number of parallel tests run on the system.

#[test]
#[serial(timeout_ms = 1000)]
fn test_serial_one() {
  // Do things
}

Nested serialised tests (i.e. a serial tagged test calling another) are supported