2
Github libtest: Wait for test threads to exit after they report completion by an...
source link: https://github.com/rust-lang/rust/pull/81367
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Otherwise we can miss bugs where a test reports that it succeeded but then panics within a TLS destructor.
Example:
use std::thread::sleep; use std::time::Duration; struct Foo; impl Drop for Foo { fn drop(&mut self) { sleep(Duration::from_secs(1)); panic!() } } thread_local!(static FOO: Foo = Foo); #[test] pub fn test() { FOO.with(|_| {}); }
Before this fix, cargo test
incorrectly reports success.
$ cargo test Finished test [unoptimized + debuginfo] target(s) in 0.01s Running target/debug/deps/panicking_test-85130fa46b54f758 running 1 test test test ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s $ echo $? 0
After this fix, the failure is visible. (The entire process is aborted due to #24479.)
$ cargo test Finished test [unoptimized + debuginfo] target(s) in 0.01s Running target/debug/deps/panicking_test-76180625bc2ee3c9 running 1 test thread 'test' panicked at 'explicit panic', src/main.rs:9:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace fatal runtime error: failed to initiate panic, error 5 error: test failed, to rerun pass '--bin panicking-test' Caused by: process didn't exit successfully: `/tmp/panicking-test/target/debug/deps/panicking_test-76180625bc2ee3c9 --nocapture` (signal: 6, SIGABRT: process abort signal) $ echo $? 101
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK