简体   繁体   中英

How to limit the number of test threads in Cargo.toml?

I have tests which share a common resource and can't be executed concurrently. These tests fail with cargo test , but work with RUST_TEST_THREADS=1 cargo test .

I can modify the tests to wait on a global mutex, but I don't want to clutter them if there is any simpler way to force cargo set this environment variable for me.

As of Rust 1.18, there is no such thing. In fact, there is not even a simpler option to disable parallel testing.
Source

However, what might help you is cargo test -- --test-threads=1 , which is the recommended way of doing what you are doing over the RUST_TEST_THREADS envvar. Keep in mind that this only sets the number of threads used for testing in addition to the main thread.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM