Attribute Macro madsim::test

source · []
#[test]
Available on crate feature macros only.
Expand description

Marks async function to be executed by runtime, suitable to test environment.

Example

#[madsim::test]
async fn my_test() {
    assert!(true);
}

Configuration

Test can be configured using the following environment variables:

  • MADSIM_TEST_SEED: Set the random seed for test.

    By default, the seed is set to the seconds since the Unix epoch.

  • MADSIM_TEST_NUM: Set the number of tests.

    The seed will increase by 1 for each test.

    By default, the number is 1.

  • MADSIM_TEST_JOBS: Set the number of jobs to run simultaneously.

    By default, the number of jobs is 1.

  • MADSIM_TEST_CONFIG: Set the config file path.

    By default, tests will use the default configuration.

  • MADSIM_TEST_TIME_LIMIT: Set the time limit for the test.

    The test will panic if time limit exceeded in the simulation.

    By default, there is no time limit.

  • MADSIM_TEST_CHECK_DETERMINISM: Enable determinism check.

    The test will be run at least twice with the same seed. If any non-determinism detected, it will panic as soon as possible.

    By default, it is disabled.