Skip to content

Commit 3d87789

Browse files
author
bors-servo
authored
Auto merge of #167 - jeanphilippeD:chunked_parallel_test, r=emilio
Run test in parallel batches
2 parents 63f8296 + 0762243 commit 3d87789

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tests/tests.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use std::io::Read;
1010
use std::path::{Path, PathBuf};
1111
use std::process;
1212

13+
const TEST_BATCH_DEFAULT_SIZE: usize = 16;
14+
1315
fn spawn_run_bindgen<P, Q, R>(run_bindgen: P, bindgen: Q, header: R) -> process::Child
1416
where P: AsRef<Path>,
1517
Q: AsRef<Path>,
@@ -83,25 +85,33 @@ fn run_bindgen_tests() {
8385
Some(Some("hpp")) => true,
8486
_ => false,
8587
}
86-
});
88+
}).collect::<Vec<_>>();
89+
90+
let batch_size = env::var("BINDGEN_TEST_BATCH_SIZE")
91+
.ok()
92+
.and_then(|x| x.parse::<usize>().ok())
93+
.unwrap_or(TEST_BATCH_DEFAULT_SIZE);
8794

88-
// Spawn one child at a time and wait on it as number of process
89-
// is the number of test files.
95+
// Spawn batch_size child to run in parallel
96+
// and wait on all of them before processing the next batch
9097

91-
let children = tests.map(|entry| {
92-
let child = spawn_run_bindgen(run_bindgen.clone(), bindgen.clone(), entry.path());
93-
(entry.path(), child)
98+
let children = tests.chunks(batch_size).map(|x| {
99+
x.iter().map(|entry| {
100+
let child = spawn_run_bindgen(run_bindgen.clone(), bindgen.clone(), entry.path());
101+
(entry.path(), child)
102+
}).collect::<Vec<_>>()
94103
});
95104

96-
let failures: Vec<_> = children
97-
.filter_map(|(path, mut child)| {
105+
let failures: Vec<_> = children.flat_map(|x| {
106+
x.into_iter().filter_map(|(path, mut child)| {
98107
let passed = child.wait()
99108
.expect("Should wait on child process")
100109
.success();
101110

102111
if passed { None } else { Some((path, child)) }
103112
})
104-
.collect();
113+
})
114+
.collect();
105115

106116
let num_failures = failures.len();
107117

0 commit comments

Comments
 (0)