Skip to content

Commit a78cb96

Browse files
committed
Run test in serial by default to not take all memory
When running all the test in parallel, all the memory on my laptop is consumed by rustc processes, my machine become unusable and the tests do not make progress. It seems to make sense to have serial by default, as the number of process depends on the number of test files. To run the test in parallel: RUN_TEST_PARALLEL=1 cargo test --feature llvm_stable
1 parent f7b5fae commit a78cb96

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

tests/tests.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,31 @@ fn run_bindgen_tests() {
8585
}
8686
});
8787

88-
// First spawn all child processes and collect them, then wait on each
89-
// one. This runs the tests in parallel rather than serially.
90-
91-
let children: Vec<_> = tests.map(|entry| {
88+
let children = tests.map(|entry| {
9289
let child = spawn_run_bindgen(run_bindgen.clone(), bindgen.clone(), entry.path());
9390
(entry.path(), child)
94-
})
95-
.collect();
96-
97-
let failures: Vec<_> = children.into_iter()
98-
.filter_map(|(path, mut child)| {
99-
let passed = child.wait()
100-
.expect("Should wait on child process")
101-
.success();
102-
103-
if passed { None } else { Some((path, child)) }
104-
})
105-
.collect();
91+
});
92+
93+
let child_wait = |(path, mut child): (PathBuf, process::Child)| {
94+
let passed = child.wait()
95+
.expect("Should wait on child process")
96+
.success();
97+
98+
if passed { None } else { Some((path, child)) }
99+
};
100+
101+
let failures: Vec<_> = if env::var("RUN_TEST_PARALLEL").is_ok() {
102+
// First spawn all child processes and collect them,
103+
// then wait on each one.
104+
children.collect::<Vec<_>>().into_iter()
105+
.filter_map(child_wait)
106+
.collect()
107+
} else {
108+
// Spawn one child at a time and wait on it.
109+
children
110+
.filter_map(child_wait)
111+
.collect()
112+
};
106113

107114
let num_failures = failures.len();
108115

0 commit comments

Comments
 (0)