jeudi 14 novembre 2019

Rust Running Some Tests Sequentially While Others in Parallel

I have several tests:

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn foo(){
        //Must be run sequentially
    }

    #[test]
    fn bar(){
        //Must be run sequentially.
    }

    #[test]
    fn baz(){
        //Can be run in parallel.
    }

    #[test]
    fn qux(){
        //Can be run in parallel.
    }
}

foo() and bar() must be run sequentially, because they might race with themselves or another test not shown.

I can prevent a race condition by only using one thread to test, cargo test -- --test-threads=1. But I don't want to do this because I'd like baz() and qux() to be run in parallel.

I could also place the #[ignore] attribute on foo() and bar(). Call cargo test to invoke baz() and qux() in parallel, then just individually run foo() and bar(), but that is a lot of work.

Is there anyway to ensure that foo() and bar() run sequentially, but all other tests run in parallel with a single invocation of cargo test? For reference here are the current attributes.

Aucun commentaire:

Enregistrer un commentaire