diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index 9c5bb8957b548..6570cadef8498 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -470,7 +470,14 @@ pub fn run_test( let supports_threads = !cfg!(target_os = "emscripten") && !cfg!(target_arch = "wasm32"); if concurrency == Concurrent::Yes && supports_threads { let cfg = thread::Builder::new().name(name.as_slice().to_owned()); - cfg.spawn(runtest).unwrap(); + if let Err(err) = cfg.spawn(runtest) { + if err.kind() == io::ErrorKind::WouldBlock { + // If we're at the thread limit, just run all tests in a single thread. + runtest(); + } else { + panic!("spawning a test thread failed: {}", err); + } + } } else { runtest(); }