libtest: Don't panic if unable to spawn thread#78165
libtest: Don't panic if unable to spawn thread#78165camelid wants to merge 4 commits intorust-lang:masterfrom
Conversation
Instead just run the test synchronously.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
library/test/src/lib.rs
Outdated
| let cfg = thread::Builder::new().name(name.as_slice().to_owned()); | ||
| cfg.spawn(runtest).unwrap(); | ||
| if cfg.spawn(runtest).is_err() { | ||
| // If we can't spawn a new thread, just run the test synchronously. |
There was a problem hiding this comment.
Should we print a message letting the user know?
|
I don't have a ton of experience with closures: what's the best way to fix this? |
|
@camelid there is not a simple way to fix it; The simplest way is probably to get |
Should be fixed now. |
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
|
@camelid can you remove 'may fix' from the commit message? This PR isn't actually fixing the same problem (although it might fix a related one). |
|
☔ The latest upstream changes (presumably #81367) made this pull request unmergeable. Please resolve the merge conflicts. |
|
There’s probably a better way, but one brute-force strategy that works without much thinking would be to encase the closure in an let runtest = Arc::new(Mutex::new(Some(move || match opts.strategy {
…
})));
…
cfg.spawn({
let runtest = Arc::clone(&runtest);
move || runtest.lock().unwrap().take().unwrap()()
})
…
runtest.lock().unwrap().take().unwrap()() |
|
@camelid Any update? I would like to take over this if you run out of
I think |
|
|
I meant thay can be used after encountering |
@hyd-dev I think it's fine to open a new PR and mention this one. |
|
err actually this is waiting-on-review, not waiting-on-author, so I don't know if there's any point to a new PR. |
This change doesn't work, so a new PR still makes sense 🙃 The reason it hasn't been reviewed is (1) it doesn't work and (2) withoutboats is taking a break. |
|
New PR: #81546 |
… r=Mark-Simulacrum
[libtest] Run the test synchronously when hitting thread limit
libtest currently panics if it hits the thread limit. This often results in spurious test failures (<code>thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" }'</code> ... `error: test failed, to rerun pass '--lib'`). This PR makes it continue to run the test synchronously if it runs out of threads.
Closes rust-lang#78165.
`@rustbot` label: A-libtest T-libs
Instead just run the test synchronously.