@@ -10,6 +10,8 @@ use std::io::Read;
10
10
use std:: path:: { Path , PathBuf } ;
11
11
use std:: process;
12
12
13
+ const TEST_BATCH_DEFAULT_SIZE : usize = 16 ;
14
+
13
15
fn spawn_run_bindgen < P , Q , R > ( run_bindgen : P , bindgen : Q , header : R ) -> process:: Child
14
16
where P : AsRef < Path > ,
15
17
Q : AsRef < Path > ,
@@ -83,25 +85,33 @@ fn run_bindgen_tests() {
83
85
Some ( Some ( "hpp" ) ) => true ,
84
86
_ => false ,
85
87
}
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 ) ;
87
94
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
90
97
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 < _ > > ( )
94
103
} ) ;
95
104
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) | {
98
107
let passed = child. wait ( )
99
108
. expect ( "Should wait on child process" )
100
109
. success ( ) ;
101
110
102
111
if passed { None } else { Some ( ( path, child) ) }
103
112
} )
104
- . collect ( ) ;
113
+ } )
114
+ . collect ( ) ;
105
115
106
116
let num_failures = failures. len ( ) ;
107
117
0 commit comments