diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-10-30 00:16:36 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-30 00:16:36 -0500 |
commit | 3d87789344b33188c786caff67e3882e1aa6f4b8 (patch) | |
tree | 9bb81df06b77b80964926ec5e3733b04c9269d05 | |
parent | 63f8296d61f4d4f521f59b6190b20f0a21504e75 (diff) | |
parent | 0762243c3b23ac5244063eef4538e8f0a3819693 (diff) |
Auto merge of #167 - jeanphilippeD:chunked_parallel_test, r=emilio
Run test in parallel batches
-rw-r--r-- | tests/tests.rs | 28 |
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(); |