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

北城余情 提交于 2019-12-08 17:11:58

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/44947914/how-to-limit-the-number-of-test-threads-in-cargo-toml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!