summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe DUFRAIGNE <j.dufraigne@gmail.com>2016-10-30 01:03:28 +0000
committerJean-Philippe DUFRAIGNE <j.dufraigne@gmail.com>2016-10-30 03:18:34 +0000
commit0762243c3b23ac5244063eef4538e8f0a3819693 (patch)
tree918b39058b4486395c6f14aa53efd60c6c7099ef
parent6ff1c1d90efc1da0529a3d4ef9e457eee97f768d (diff)
Run test in parallel batches
Follow review suggestion to use chunks to run test in parallel. Set default to 16 which works well even on my limited laptop, and which should benefit better machine. To run with a different batch size: BINDGEN_TEST_BATCH_SIZE=32 cargo test On my machine: 1 parallel test takes 3'53 2 parallel test takes 2'10 8 parallel test takes 2'08 32 parallel test takes 2'07
-rw-r--r--tests/tests.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/tests/tests.rs b/tests/tests.rs
index 1f8864e0..003c0f1a 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -10,6 +10,8 @@ use std::io::Read;
use std::path::{Path, PathBuf};
use std::process;
+const TEST_BATCH_DEFAULT_SIZE: usize = 16;
+
fn spawn_run_bindgen<P, Q, R>(run_bindgen: P, bindgen: Q, header: R) -> process::Child
where P: AsRef<Path>,
Q: AsRef<Path>,
@@ -83,25 +85,33 @@ fn run_bindgen_tests() {
Some(Some("hpp")) => true,
_ => false,
}
- });
+ }).collect::<Vec<_>>();
+
+ let batch_size = env::var("BINDGEN_TEST_BATCH_SIZE")
+ .ok()
+ .and_then(|x| x.parse::<usize>().ok())
+ .unwrap_or(TEST_BATCH_DEFAULT_SIZE);
- // Spawn one child at a time and wait on it as number of process
- // is the number of test files.
+ // Spawn batch_size child to run in parallel
+ // and wait on all of them before processing the next batch
- let children = tests.map(|entry| {
- let child = spawn_run_bindgen(run_bindgen.clone(), bindgen.clone(), entry.path());
- (entry.path(), child)
+ let children = tests.chunks(batch_size).map(|x| {
+ x.iter().map(|entry| {
+ let child = spawn_run_bindgen(run_bindgen.clone(), bindgen.clone(), entry.path());
+ (entry.path(), child)
+ }).collect::<Vec<_>>()
});
- let failures: Vec<_> = children
- .filter_map(|(path, mut child)| {
+ let failures: Vec<_> = children.flat_map(|x| {
+ x.into_iter().filter_map(|(path, mut child)| {
let passed = child.wait()
.expect("Should wait on child process")
.success();
if passed { None } else { Some((path, child)) }
})
- .collect();
+ })
+ .collect();
let num_failures = failures.len();