[英]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
. 这些测试通过
cargo test
测试失败,但使用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. 我可以修改测试以等待全局互斥,但如果有任何更简单的方法强制
cargo
为我设置此环境变量,我不想混淆它们。
As of Rust 1.18, there is no such thing. 从Rust 1.18开始,没有这样的东西。 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. 但是,对于
cargo test -- --test-threads=1
可能有什么帮助cargo test -- --test-threads=1
,这是你在RUST_TEST_THREADS
envvar上做的事情的推荐方法。 Keep in mind that this only sets the number of threads used for testing in addition to the main thread. 请记住, 除了主线程之外 ,这仅设置用于测试的线程数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.