Skip to content

Commit 753fc1b

Browse files
committed
Run subtests before entirely new tests
1 parent 2fb14f5 commit 753fc1b

File tree

4 files changed

+235
-218
lines changed

4 files changed

+235
-218
lines changed

src/core.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,17 @@ pub enum CrateType {
9494

9595
/// A generic multithreaded runner that has a thread for producing work,
9696
/// a thread for collecting work, and `num_threads` threads for doing the work.
97-
pub fn run_and_collect<SUBMISSION: Send, RESULT: Send>(
97+
pub fn run_and_collect<const N: usize, SUBMISSION: Send, RESULT: Send>(
9898
num_threads: NonZeroUsize,
99-
submitter: impl FnOnce(Sender<SUBMISSION>) + Send,
100-
runner: impl Sync + Fn(&Receiver<SUBMISSION>, Sender<RESULT>) -> Result<()>,
99+
submitter: impl FnOnce([Sender<SUBMISSION>; N]) + Send,
100+
runner: impl Sync + Fn(&[Receiver<SUBMISSION>; N], Sender<RESULT>) -> Result<()>,
101101
collector: impl FnOnce(Receiver<RESULT>) + Send,
102102
) -> Result<()> {
103103
// A channel for files to process
104-
let (submit, receive) = unbounded();
104+
let (submit, receive): (Vec<_>, Vec<_>) = std::iter::repeat_with(unbounded).take(N).unzip();
105+
let receive = receive[..].try_into().unwrap();
106+
let mut submit = submit.into_iter();
107+
let submit = std::array::from_fn(|_| submit.next().unwrap());
105108

106109
thread::scope(|s| {
107110
// Create a thread that is in charge of walking the directory and submitting jobs.
@@ -119,7 +122,7 @@ pub fn run_and_collect<SUBMISSION: Send, RESULT: Send>(
119122
// Create N worker threads that receive files to test.
120123
for _ in 0..num_threads.get() {
121124
let finished_files_sender = finished_files_sender.clone();
122-
threads.push(s.spawn(|| runner(&receive, finished_files_sender)));
125+
threads.push(s.spawn(|| runner(receive, finished_files_sender)));
123126
}
124127

125128
for thread in threads {

src/lib.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub use color_eyre::eyre::Result;
1717
pub use core::run_and_collect;
1818
pub use core::CrateType;
1919
use crossbeam_channel::Sender;
20+
use crossbeam_channel::TryRecvError;
2021
pub use filter::Match;
2122
use per_test_config::TestConfig;
2223
use spanned::Spanned;
@@ -198,12 +199,12 @@ pub fn run_tests_generic(
198199
let mut filtered = 0;
199200
core::run_and_collect(
200201
num_threads,
201-
|submit| {
202+
|[submit, priority_submit]| {
202203
let mut todo = VecDeque::new();
203204

204205
let configs: Vec<_> = configs
205206
.into_iter()
206-
.map(|config| Arc::new(BuildManager::new(config, submit.clone())))
207+
.map(|config| Arc::new(BuildManager::new(config, priority_submit.clone())))
207208
.collect();
208209
for build_manager in &configs {
209210
todo.push_back((
@@ -287,11 +288,24 @@ pub fn run_tests_generic(
287288
}
288289
}
289290
},
290-
|receive, finished_files_sender| -> Result<()> {
291-
for closure in receive {
292-
closure(&finished_files_sender)?;
291+
|[receive, priority_receive], finished_files_sender| -> Result<()> {
292+
loop {
293+
for closure in priority_receive.try_iter() {
294+
closure(&finished_files_sender)?;
295+
}
296+
match receive.try_recv() {
297+
Ok(closure) => {
298+
closure(&finished_files_sender)?;
299+
}
300+
Err(TryRecvError::Empty) => {}
301+
Err(TryRecvError::Disconnected) => {
302+
for closure in priority_receive {
303+
closure(&finished_files_sender)?;
304+
}
305+
return Ok(());
306+
}
307+
}
293308
}
294-
Ok(())
295309
},
296310
|finished_files_recv| {
297311
for run in finished_files_recv {

0 commit comments

Comments
 (0)