Skip to content

Commit 8a86e88

Browse files
committed
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
1 parent 6ff1c1d commit 8a86e88

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

tests/tests.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,35 @@ fn run_bindgen_tests() {
8383
Some(Some("hpp")) => true,
8484
_ => false,
8585
}
86+
}).collect::<Vec<_>>();
87+
88+
let batch_size = env::var("BINDGEN_TEST_BATCH_SIZE")
89+
.ok()
90+
.map(|x| x.parse::<usize>().ok())
91+
.unwrap_or(None)
92+
.unwrap_or(16);
93+
94+
// Spawn batch_size (default 16) child to run in parallel
95+
// and wait on all of them before processing the next batch
96+
97+
let children = tests.chunks(batch_size).map(|x| {
98+
x.iter().map(|entry| {
99+
let child = spawn_run_bindgen(run_bindgen.clone(), bindgen.clone(), entry.path());
100+
(entry.path(), child)
101+
}).collect::<Vec<_>>()
86102
});
87103

88-
// Spawn one child at a time and wait on it as number of process
89-
// is the number of test files.
90-
91-
let children = tests.map(|entry| {
92-
let child = spawn_run_bindgen(run_bindgen.clone(), bindgen.clone(), entry.path());
93-
(entry.path(), child)
94-
});
95-
96-
let failures: Vec<_> = children
97-
.filter_map(|(path, mut child)| {
104+
let failures: Vec<_> = children.map(|x| {
105+
x.into_iter().filter_map(|(path, mut child)| {
98106
let passed = child.wait()
99107
.expect("Should wait on child process")
100108
.success();
101109

102110
if passed { None } else { Some((path, child)) }
103111
})
104-
.collect();
112+
})
113+
.flat_map(|x| x )
114+
.collect();
105115

106116
let num_failures = failures.len();
107117

0 commit comments

Comments
 (0)