Skip to content

Commit 2587d3f

Browse files
author
hyd-dev
committed
[libtest] Run the test synchronously when hitting thread limit
1 parent 1b1ed35 commit 2587d3f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

test/src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,18 @@ pub fn run_test(
506506
let supports_threads = !cfg!(target_os = "emscripten") && !cfg!(target_arch = "wasm32");
507507
if concurrency == Concurrent::Yes && supports_threads {
508508
let cfg = thread::Builder::new().name(name.as_slice().to_owned());
509-
Some(cfg.spawn(runtest).unwrap())
509+
let mut runtest = Arc::new(Mutex::new(Some(runtest)));
510+
let runtest2 = runtest.clone();
511+
match cfg.spawn(move || runtest2.lock().unwrap().take().unwrap()()) {
512+
Ok(handle) => Some(handle),
513+
Err(e) if e.kind() == io::ErrorKind::WouldBlock => {
514+
// `ErrorKind::WouldBlock` means hitting the thread limit on some
515+
// platforms, so run the test synchronously here instead.
516+
Arc::get_mut(&mut runtest).unwrap().get_mut().unwrap().take().unwrap()();
517+
None
518+
}
519+
Err(e) => panic!("failed to spawn thread to run test: {}", e),
520+
}
510521
} else {
511522
runtest();
512523
None

0 commit comments

Comments
 (0)