Do not spawn a thread if we do not use concurrency

This commit is contained in:
Ralf Jung
2018-11-26 17:03:51 +01:00
parent f460eac66e
commit e9caa8ed91

View File

@@ -1150,7 +1150,7 @@ where
while !remaining.is_empty() { while !remaining.is_empty() {
let test = remaining.pop().unwrap(); let test = remaining.pop().unwrap();
callback(TeWait(test.desc.clone()))?; callback(TeWait(test.desc.clone()))?;
run_test(opts, !opts.run_tests, test, tx.clone()); run_test(opts, !opts.run_tests, test, tx.clone(), /*concurrency*/false);
let (test, result, stdout) = rx.recv().unwrap(); let (test, result, stdout) = rx.recv().unwrap();
callback(TeResult(test, result, stdout))?; callback(TeResult(test, result, stdout))?;
} }
@@ -1161,7 +1161,7 @@ where
let timeout = Instant::now() + Duration::from_secs(TEST_WARN_TIMEOUT_S); let timeout = Instant::now() + Duration::from_secs(TEST_WARN_TIMEOUT_S);
running_tests.insert(test.desc.clone(), timeout); running_tests.insert(test.desc.clone(), timeout);
callback(TeWait(test.desc.clone()))?; //here no pad callback(TeWait(test.desc.clone()))?; //here no pad
run_test(opts, !opts.run_tests, test, tx.clone()); run_test(opts, !opts.run_tests, test, tx.clone(), /*concurrency*/true);
pending += 1; pending += 1;
} }
@@ -1193,7 +1193,7 @@ where
// All benchmarks run at the end, in serial. // All benchmarks run at the end, in serial.
for b in filtered_benchs { for b in filtered_benchs {
callback(TeWait(b.desc.clone()))?; callback(TeWait(b.desc.clone()))?;
run_test(opts, false, b, tx.clone()); run_test(opts, false, b, tx.clone(), /*concurrency*/true);
let (test, result, stdout) = rx.recv().unwrap(); let (test, result, stdout) = rx.recv().unwrap();
callback(TeResult(test, result, stdout))?; callback(TeResult(test, result, stdout))?;
} }
@@ -1395,6 +1395,7 @@ pub fn run_test(
force_ignore: bool, force_ignore: bool,
test: TestDescAndFn, test: TestDescAndFn,
monitor_ch: Sender<MonitorMsg>, monitor_ch: Sender<MonitorMsg>,
concurrency: bool,
) { ) {
let TestDescAndFn { desc, testfn } = test; let TestDescAndFn { desc, testfn } = test;
@@ -1411,6 +1412,7 @@ pub fn run_test(
monitor_ch: Sender<MonitorMsg>, monitor_ch: Sender<MonitorMsg>,
nocapture: bool, nocapture: bool,
testfn: Box<dyn FnBox() + Send>, testfn: Box<dyn FnBox() + Send>,
concurrency: bool,
) { ) {
// Buffer for capturing standard I/O // Buffer for capturing standard I/O
let data = Arc::new(Mutex::new(Vec::new())); let data = Arc::new(Mutex::new(Vec::new()));
@@ -1445,7 +1447,7 @@ pub fn run_test(
// the test synchronously, regardless of the concurrency // the test synchronously, regardless of the concurrency
// level. // level.
let supports_threads = !cfg!(target_os = "emscripten") && !cfg!(target_arch = "wasm32"); let supports_threads = !cfg!(target_os = "emscripten") && !cfg!(target_arch = "wasm32");
if supports_threads { if concurrency && supports_threads {
let cfg = thread::Builder::new().name(name.as_slice().to_owned()); let cfg = thread::Builder::new().name(name.as_slice().to_owned());
cfg.spawn(runtest).unwrap(); cfg.spawn(runtest).unwrap();
} else { } else {
@@ -1466,13 +1468,14 @@ pub fn run_test(
} }
DynTestFn(f) => { DynTestFn(f) => {
let cb = move || __rust_begin_short_backtrace(f); let cb = move || __rust_begin_short_backtrace(f);
run_test_inner(desc, monitor_ch, opts.nocapture, Box::new(cb)) run_test_inner(desc, monitor_ch, opts.nocapture, Box::new(cb), concurrency)
} }
StaticTestFn(f) => run_test_inner( StaticTestFn(f) => run_test_inner(
desc, desc,
monitor_ch, monitor_ch,
opts.nocapture, opts.nocapture,
Box::new(move || __rust_begin_short_backtrace(f)), Box::new(move || __rust_begin_short_backtrace(f)),
concurrency,
), ),
} }
} }