From db10a866666f71b70194b1cbbbec1150574ad2bd Mon Sep 17 00:00:00 2001 From: Shiv Jha-Mathur Date: Sun, 11 Jun 2017 21:16:08 +0530 Subject: [PATCH 01/11] Add `serial' to `BUILTIN_ATTRIBUTES'. --- src/libsyntax/feature_gate.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index b2f52d11db2b1..1d084da0965c1 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -530,6 +530,7 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG ("derive", Normal, Ungated), ("should_panic", Normal, Ungated), ("ignore", Normal, Ungated), + ("serial", Normal, Ungated), ("no_implicit_prelude", Normal, Ungated), ("reexport_test_harness_main", Normal, Ungated), ("link_args", Normal, Ungated), From ff420f83e238d97024964570904e99231b88b669 Mon Sep 17 00:00:00 2001 From: Shiv Jha-Mathur Date: Sun, 11 Jun 2017 21:17:37 +0530 Subject: [PATCH 02/11] Add `serial' to `Test' struct and populate it. --- src/libsyntax/test.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index a0d1785c6ff14..afb35fa95b360 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -52,7 +52,8 @@ struct Test { path: Vec , bench: bool, ignore: bool, - should_panic: ShouldPanic + should_panic: ShouldPanic, + serial: bool } struct TestCtxt<'a> { @@ -133,7 +134,8 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { path: self.cx.path.clone(), bench: is_bench_fn(&self.cx, &i), ignore: is_ignored(&i), - should_panic: should_panic(&i, &self.cx) + should_panic: should_panic(&i, &self.cx), + serial: is_serial(&i) }; self.cx.testfns.push(test); self.tests.push(i.ident); @@ -383,6 +385,10 @@ fn is_ignored(i: &ast::Item) -> bool { i.attrs.iter().any(|attr| attr.check_name("ignore")) } +fn is_serial(i: &ast::Item) -> bool { + i.attrs.iter().any(|attr| attr.check_name("serial")) +} + fn should_panic(i: &ast::Item, cx: &TestCtxt) -> ShouldPanic { match i.attrs.iter().find(|attr| attr.check_name("should_panic")) { Some(attr) => { @@ -655,6 +661,7 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P { let should_panic_path = |name| { ecx.path(span, vec![self_id, test_id, ecx.ident_of("ShouldPanic"), ecx.ident_of(name)]) }; + let serial_expr = ecx.expr_bool(span, test.serial); let fail_expr = match test.should_panic { ShouldPanic::No => ecx.expr_path(should_panic_path("No")), ShouldPanic::Yes(msg) => { @@ -675,7 +682,8 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> P { test_path("TestDesc"), vec![field("name", name_expr), field("ignore", ignore_expr), - field("should_panic", fail_expr)]); + field("should_panic", fail_expr), + field("serial", serial_expr)]); let mut visible_path = match cx.toplevel_reexport { From 01555dd37e0d6f91f52bad45d2a6cc67011d9281 Mon Sep 17 00:00:00 2001 From: Shiv Jha-Mathur Date: Sun, 11 Jun 2017 21:18:09 +0530 Subject: [PATCH 03/11] Add `serial' in `libtest' and `librustdoc'. --- src/librustdoc/test.rs | 1 + src/libtest/lib.rs | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index cfe2fad0fa469..fb5e83551b2db 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -499,6 +499,7 @@ impl Collector { ignore: should_ignore, // compiler failures are test failures should_panic: testing::ShouldPanic::No, + serial: false, }, testfn: testing::DynTestFn(box move |()| { let panic = io::set_panic(None); diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index ef048ac8ca355..f9fd3691193f6 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -212,6 +212,7 @@ pub struct TestDesc { pub name: TestName, pub ignore: bool, pub should_panic: ShouldPanic, + pub serial: bool, } #[derive(Clone)] @@ -423,7 +424,10 @@ Test Attributes: #[ignore] - When applied to a function which is already attributed as a test, then the test runner will ignore these tests during normal test runs. Running with --ignored will run these - tests."#, + tests. + #[serial] - When applied to a function which is already attributed as a + test, then the test runner will not run these tests in + parallel with any other tests."#, usage = getopts::usage(&message, &optgroups())); } @@ -944,12 +948,14 @@ fn should_sort_failures_before_printing_them() { name: StaticTestName("a"), ignore: false, should_panic: ShouldPanic::No, + serial: false, }; let test_b = TestDesc { name: StaticTestName("b"), ignore: false, should_panic: ShouldPanic::No, + serial: false, }; let mut st = ConsoleTestState { @@ -1705,6 +1711,7 @@ mod tests { name: StaticTestName("whatever"), ignore: true, should_panic: ShouldPanic::No, + serial: false, }, testfn: DynTestFn(Box::new(move |()| f())), }; @@ -1722,6 +1729,7 @@ mod tests { name: StaticTestName("whatever"), ignore: true, should_panic: ShouldPanic::No, + serial: false, }, testfn: DynTestFn(Box::new(move |()| f())), }; @@ -1741,6 +1749,7 @@ mod tests { name: StaticTestName("whatever"), ignore: false, should_panic: ShouldPanic::Yes, + serial: false, }, testfn: DynTestFn(Box::new(move |()| f())), }; @@ -1760,6 +1769,7 @@ mod tests { name: StaticTestName("whatever"), ignore: false, should_panic: ShouldPanic::YesWithMessage("error message"), + serial: false, }, testfn: DynTestFn(Box::new(move |()| f())), }; @@ -1781,6 +1791,7 @@ mod tests { name: StaticTestName("whatever"), ignore: false, should_panic: ShouldPanic::YesWithMessage(expected), + serial: false, }, testfn: DynTestFn(Box::new(move |()| f())), }; @@ -1798,6 +1809,7 @@ mod tests { name: StaticTestName("whatever"), ignore: false, should_panic: ShouldPanic::Yes, + serial: false, }, testfn: DynTestFn(Box::new(move |()| f())), }; @@ -1831,6 +1843,7 @@ mod tests { name: StaticTestName("1"), ignore: true, should_panic: ShouldPanic::No, + serial: false, }, testfn: DynTestFn(Box::new(move |()| {})), }, @@ -1839,6 +1852,7 @@ mod tests { name: StaticTestName("2"), ignore: false, should_panic: ShouldPanic::No, + serial: false, }, testfn: DynTestFn(Box::new(move |()| {})), }]; @@ -1862,6 +1876,7 @@ mod tests { name: StaticTestName(name), ignore: false, should_panic: ShouldPanic::No, + serial: false, }, testfn: DynTestFn(Box::new(move |()| {})) }) @@ -1943,6 +1958,7 @@ mod tests { name: DynTestName((*name).clone()), ignore: false, should_panic: ShouldPanic::No, + serial: false, }, testfn: DynTestFn(Box::new(move |()| testfn())), }; From e17a1f81e68afd3132d1cb60869a923c9cedd9f2 Mon Sep 17 00:00:00 2001 From: Shiv Jha-Mathur Date: Sun, 11 Jun 2017 22:29:26 +0530 Subject: [PATCH 04/11] Add awkward repeated code to execute serial tests serially. --- src/libtest/lib.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index f9fd3691193f6..97aa04acc42f4 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -1069,7 +1069,9 @@ pub fn run_tests(opts: &TestOpts, tests: Vec, mut callback: F) None => get_concurrency(), }; - let mut remaining = filtered_tests; + let partitioned = filtered_tests.into_iter().partition(|t| t.desc.serial); + let serial: Vec<_> = partitioned.0; + let mut remaining: Vec<_> = partitioned.1; remaining.reverse(); let mut pending = 0; @@ -1139,6 +1141,34 @@ pub fn run_tests(opts: &TestOpts, tests: Vec, mut callback: F) pending -= 1; } + for test in serial { + callback(TeWait(test.desc.clone(), test.testfn.padding()))?; + let timeout = Instant::now() + Duration::from_secs(TEST_WARN_TIMEOUT_S); + running_tests.insert(test.desc.clone(), timeout); + run_test(opts, !opts.run_tests, test, tx.clone()); + + let mut res; + loop { + if let Some(timeout) = calc_timeout(&running_tests) { + res = rx.recv_timeout(timeout); + for test in get_timed_out_tests(&mut running_tests) { + callback(TeTimeout(test))?; + } + if res != Err(RecvTimeoutError::Timeout) { + break; + } + } else { + res = rx.recv().map_err(|_| RecvTimeoutError::Disconnected); + break; + } + } + + let (desc, result, stdout) = res.unwrap(); + running_tests.remove(&desc); + + callback(TeResult(desc, result, stdout))?; + } + if opts.bench_benchmarks { // All benchmarks run at the end, in serial. // (this includes metric fns) From 20075117d47bd49cb4703ad1c66f92ebc74a1e00 Mon Sep 17 00:00:00 2001 From: Shiv Jha-Mathur Date: Mon, 12 Jun 2017 01:22:54 +0530 Subject: [PATCH 05/11] Add non-working serial stress test. --- src/libtest/lib.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 97aa04acc42f4..0fdd5a9cb157f 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -2013,6 +2013,65 @@ mod tests { } } + #[test] + pub fn stress_test_serial_tests() { + use std::env; + use std::fs; + use std::time::{SystemTime, UNIX_EPOCH}; + use std::panic::{AssertUnwindSafe, catch_unwind}; + use std::path::PathBuf; + use super::{TestEvent, TestResult, run_tests}; + + fn test_fn(path: PathBuf) { + use std::fs::File; + use std::io::Write; + + { + let mut f = File::create(&path) + .expect("create stress test file"); + f.write_all(b"stress") + .expect("write to stress test file"); + } + } + + let mut opts = TestOpts::new(); + opts.run_tests = true; + + let limit = 100; + + let dir = env::temp_dir(); + let path = dir.join(format!("rust-stress-test-file-{}", SystemTime::now().duration_since(UNIX_EPOCH).expect("time since Unix epoch").as_secs())); + + let tests = (0..limit) + .map(|n| TestDescAndFn { + desc: TestDesc { + name: DynTestName(format!("stress_{:?}", n)), + ignore: false, + should_panic: ShouldPanic::No, + serial: true, + }, + testfn: DynTestFn(Box::new(|()| { test_fn(path.to_owned()) })) + }) + .collect::>(); + + let result = catch_unwind(AssertUnwindSafe(|| { + run_tests(&opts, tests, |e| { + match e { + TestEvent::TeFilteredOut(n) if n > 0 => panic!("filtered out"), + TestEvent::TeTimeout(_) => panic!("timeout"), + TestEvent::TeResult(_, ref result, _) if result != &TestResult::TrOk => panic!("result not okay"), + _ => Ok(()) + } + }); + })); + + if path.exists() { + fs::remove_file(&path).expect("remove file"); + } + + result.unwrap() + } + #[test] pub fn test_metricmap_compare() { let mut m1 = MetricMap::new(); From 3df845761402bc03618e28dc5ab17c1c72ad50ea Mon Sep 17 00:00:00 2001 From: Shiv Jha-Mathur Date: Mon, 12 Jun 2017 12:23:27 +0530 Subject: [PATCH 06/11] Update TestDesc creation in `compiletest'. --- src/tools/compiletest/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 1bb0b765f9f1c..6986913b0a8e1 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -475,6 +475,7 @@ pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn name: make_test_name(config, testpaths), ignore: ignore, should_panic: should_panic, + serial: false, }, testfn: make_test_closure(config, testpaths), } From e414123a10d60ef11ac4dc1dc8f74f8ea4163e18 Mon Sep 17 00:00:00 2001 From: Shiv Jha-Mathur Date: Mon, 12 Jun 2017 12:23:50 +0530 Subject: [PATCH 07/11] Replace file-based stress test with Arc + RwLock-based test. --- src/libtest/lib.rs | 68 ++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 0fdd5a9cb157f..81e7f33834d9d 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -2015,61 +2015,45 @@ mod tests { #[test] pub fn stress_test_serial_tests() { - use std::env; - use std::fs; - use std::time::{SystemTime, UNIX_EPOCH}; - use std::panic::{AssertUnwindSafe, catch_unwind}; - use std::path::PathBuf; use super::{TestEvent, TestResult, run_tests}; - - fn test_fn(path: PathBuf) { - use std::fs::File; - use std::io::Write; - - { - let mut f = File::create(&path) - .expect("create stress test file"); - f.write_all(b"stress") - .expect("write to stress test file"); - } - } + use std::sync::{Arc, RwLock}; let mut opts = TestOpts::new(); opts.run_tests = true; let limit = 100; - let dir = env::temp_dir(); - let path = dir.join(format!("rust-stress-test-file-{}", SystemTime::now().duration_since(UNIX_EPOCH).expect("time since Unix epoch").as_secs())); + let lock = Arc::new(RwLock::new(0)); let tests = (0..limit) - .map(|n| TestDescAndFn { - desc: TestDesc { - name: DynTestName(format!("stress_{:?}", n)), - ignore: false, - should_panic: ShouldPanic::No, - serial: true, - }, - testfn: DynTestFn(Box::new(|()| { test_fn(path.to_owned()) })) - }) - .collect::>(); + .map(|n| { + let lock = lock.clone(); - let result = catch_unwind(AssertUnwindSafe(|| { - run_tests(&opts, tests, |e| { - match e { - TestEvent::TeFilteredOut(n) if n > 0 => panic!("filtered out"), - TestEvent::TeTimeout(_) => panic!("timeout"), - TestEvent::TeResult(_, ref result, _) if result != &TestResult::TrOk => panic!("result not okay"), - _ => Ok(()) + TestDescAndFn { + desc: TestDesc { + name: DynTestName(format!("stress_{:?}", n)), + ignore: false, + should_panic: ShouldPanic::No, + serial: true, + }, + testfn: DynTestFn(Box::new(move |()| { + let mut c = lock.write().unwrap(); + *c += 1; + })) } - }); - })); + }) + .collect::>(); - if path.exists() { - fs::remove_file(&path).expect("remove file"); - } + run_tests(&opts, tests, |e| { + match e { + TestEvent::TeFilteredOut(n) if n > 0 => panic!("filtered out"), + TestEvent::TeTimeout(_) => panic!("timeout"), + TestEvent::TeResult(_, ref result, _) if result != &TestResult::TrOk => panic!("result not okay"), + _ => Ok(()) + } + }).unwrap(); - result.unwrap() + assert_eq!(*(*lock).read().unwrap(), limit); } #[test] From 2053fcd90ecbd7c78a210e5ceed6537c8d2104ca Mon Sep 17 00:00:00 2001 From: Shiv Jha-Mathur Date: Tue, 13 Jun 2017 01:37:42 +0530 Subject: [PATCH 08/11] Add concurrent testing test. --- src/libtest/lib.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 81e7f33834d9d..b2d6ab92dcafb 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -2020,6 +2020,7 @@ mod tests { let mut opts = TestOpts::new(); opts.run_tests = true; + opts.test_threads = Some(100); let limit = 100; @@ -2056,6 +2057,71 @@ mod tests { assert_eq!(*(*lock).read().unwrap(), limit); } + #[test] + pub fn run_concurrent_tests_concurrently() { + use super::{TestEvent, TestResult, run_tests}; + use std::sync::{Arc, RwLock}; + use std::thread::sleep; + use std::time::Duration; + + let mut opts = TestOpts::new(); + opts.run_tests = true; + opts.test_threads = Some(2); + + let lock = Arc::new(RwLock::new(0)); + + let lock2 = lock.clone(); + let lock3 = lock.clone(); + + let tests = vec![ + TestDescAndFn { + desc: TestDesc { + name: DynTestName("first".to_string()), + ignore: false, + should_panic: ShouldPanic::No, + serial: false, + }, + testfn: DynTestFn(Box::new(move |()| { + let mut c = lock2.write().unwrap(); + sleep(Duration::from_millis(1000)); + *c += 1 + })) + }, + TestDescAndFn { + desc: TestDesc { + name: DynTestName("second".to_string()), + ignore: false, + should_panic: ShouldPanic::No, + serial: false, + }, + testfn: DynTestFn(Box::new(move |()| { + sleep(Duration::from_millis(500)); + let mut c = lock3.write().unwrap(); + *c += 1 + })) + } + ]; + + run_tests(&opts, tests, |e| { + match e { + TestEvent::TeFilteredOut(n) if n > 0 => panic!("filtered out"), + TestEvent::TeTimeout(_) => panic!("timeout"), + TestEvent::TeResult(ref desc, ref result, _) => { // XXX this is ridiculous + if let DynTestName(ref n) = desc.name { + if result != &TestResult::TrFailed && *n == "second".to_string() { + panic!("Test passed somehow"); + } else { + Ok(()) + } + } else { + Ok(()) + } + } + _ => Ok(()) + } + }).unwrap(); + } + #[test] pub fn test_metricmap_compare() { let mut m1 = MetricMap::new(); From 6e1ff8ef9b544041fee12e3cccc1cbc92a7e3c40 Mon Sep 17 00:00:00 2001 From: Shiv Jha-Mathur Date: Tue, 13 Jun 2017 14:44:20 +0530 Subject: [PATCH 09/11] Simplify `run_concurrent_tests_concurrently'. --- src/libtest/lib.rs | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index b2d6ab92dcafb..667d820de8c2d 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -2060,18 +2060,15 @@ mod tests { #[test] pub fn run_concurrent_tests_concurrently() { use super::{TestEvent, TestResult, run_tests}; - use std::sync::{Arc, RwLock}; use std::thread::sleep; use std::time::Duration; + use std::sync::mpsc::channel; let mut opts = TestOpts::new(); opts.run_tests = true; opts.test_threads = Some(2); - let lock = Arc::new(RwLock::new(0)); - - let lock2 = lock.clone(); - let lock3 = lock.clone(); + let (tx, rx) = channel::<()>(); let tests = vec![ TestDescAndFn { @@ -2082,9 +2079,7 @@ mod tests { serial: false, }, testfn: DynTestFn(Box::new(move |()| { - let mut c = lock2.write().unwrap(); - sleep(Duration::from_millis(1000)); - *c += 1 + rx.recv_timeout(Duration::from_secs(1)).unwrap(); })) }, TestDescAndFn { @@ -2095,28 +2090,17 @@ mod tests { serial: false, }, testfn: DynTestFn(Box::new(move |()| { - sleep(Duration::from_millis(500)); - let mut c = lock3.write().unwrap(); - *c += 1 + sleep(Duration::from_millis(100)); + tx.send(()).unwrap(); })) - } + }, ]; run_tests(&opts, tests, |e| { match e { TestEvent::TeFilteredOut(n) if n > 0 => panic!("filtered out"), TestEvent::TeTimeout(_) => panic!("timeout"), - TestEvent::TeResult(ref desc, ref result, _) => { // XXX this is ridiculous - if let DynTestName(ref n) = desc.name { - if result != &TestResult::TrFailed && *n == "second".to_string() { - panic!("Test passed somehow"); - } else { - Ok(()) - } - } else { - Ok(()) - } - } + TestEvent::TeResult(_, ref result, _) if result != &TestResult::TrOk => panic!("result not okay"), _ => Ok(()) } }).unwrap(); From 9aade483c7ed6a61519a6df6be950752146518be Mon Sep 17 00:00:00 2001 From: Shiv Jha-Mathur Date: Tue, 13 Jun 2017 21:27:18 +0530 Subject: [PATCH 10/11] Tidy up. --- src/libtest/lib.rs | 60 ++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 667d820de8c2d..114ed126ee0b6 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -1141,33 +1141,33 @@ pub fn run_tests(opts: &TestOpts, tests: Vec, mut callback: F) pending -= 1; } - for test in serial { - callback(TeWait(test.desc.clone(), test.testfn.padding()))?; - let timeout = Instant::now() + Duration::from_secs(TEST_WARN_TIMEOUT_S); - running_tests.insert(test.desc.clone(), timeout); - run_test(opts, !opts.run_tests, test, tx.clone()); - - let mut res; - loop { - if let Some(timeout) = calc_timeout(&running_tests) { - res = rx.recv_timeout(timeout); - for test in get_timed_out_tests(&mut running_tests) { - callback(TeTimeout(test))?; - } - if res != Err(RecvTimeoutError::Timeout) { - break; - } - } else { - res = rx.recv().map_err(|_| RecvTimeoutError::Disconnected); - break; - } - } - - let (desc, result, stdout) = res.unwrap(); - running_tests.remove(&desc); - - callback(TeResult(desc, result, stdout))?; - } + for test in serial { + callback(TeWait(test.desc.clone(), test.testfn.padding()))?; + let timeout = Instant::now() + Duration::from_secs(TEST_WARN_TIMEOUT_S); + running_tests.insert(test.desc.clone(), timeout); + run_test(opts, !opts.run_tests, test, tx.clone()); + + let mut res; + loop { + if let Some(timeout) = calc_timeout(&running_tests) { + res = rx.recv_timeout(timeout); + for test in get_timed_out_tests(&mut running_tests) { + callback(TeTimeout(test))?; + } + if res != Err(RecvTimeoutError::Timeout) { + break; + } + } else { + res = rx.recv().map_err(|_| RecvTimeoutError::Disconnected); + break; + } + } + + let (desc, result, stdout) = res.unwrap(); + running_tests.remove(&desc); + + callback(TeResult(desc, result, stdout))?; + } if opts.bench_benchmarks { // All benchmarks run at the end, in serial. @@ -2049,7 +2049,8 @@ mod tests { match e { TestEvent::TeFilteredOut(n) if n > 0 => panic!("filtered out"), TestEvent::TeTimeout(_) => panic!("timeout"), - TestEvent::TeResult(_, ref result, _) if result != &TestResult::TrOk => panic!("result not okay"), + TestEvent::TeResult(_, ref result, _) if result != &TestResult::TrOk => + panic!("result not okay"), _ => Ok(()) } }).unwrap(); @@ -2100,7 +2101,8 @@ mod tests { match e { TestEvent::TeFilteredOut(n) if n > 0 => panic!("filtered out"), TestEvent::TeTimeout(_) => panic!("timeout"), - TestEvent::TeResult(_, ref result, _) if result != &TestResult::TrOk => panic!("result not okay"), + TestEvent::TeResult(_, ref result, _) if result != &TestResult::TrOk => + panic!("result not okay"), _ => Ok(()) } }).unwrap(); From 34695f8cfa7d4d26039b08d9271d92f0ca13d09f Mon Sep 17 00:00:00 2001 From: Shiv Jha-Mathur Date: Wed, 14 Jun 2017 23:56:25 +0530 Subject: [PATCH 11/11] Move new imports out of functions. --- src/libtest/lib.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 114ed126ee0b6..e9a6f931fc92e 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -1726,8 +1726,11 @@ pub mod bench { mod tests { use test::{TrFailed, TrFailedMsg, TrIgnored, TrOk, filter_tests, parse_opts, TestDesc, TestDescAndFn, TestOpts, run_test, MetricMap, StaticTestName, DynTestName, - DynTestFn, ShouldPanic}; + DynTestFn, ShouldPanic, TestResult}; + use super::{TestEvent, run_tests}; use std::sync::mpsc::channel; + use std::sync::{Arc, RwLock}; + use std::thread::sleep; use bench; use Bencher; @@ -2015,9 +2018,6 @@ mod tests { #[test] pub fn stress_test_serial_tests() { - use super::{TestEvent, TestResult, run_tests}; - use std::sync::{Arc, RwLock}; - let mut opts = TestOpts::new(); opts.run_tests = true; opts.test_threads = Some(100); @@ -2060,10 +2060,7 @@ mod tests { #[test] pub fn run_concurrent_tests_concurrently() { - use super::{TestEvent, TestResult, run_tests}; - use std::thread::sleep; use std::time::Duration; - use std::sync::mpsc::channel; let mut opts = TestOpts::new(); opts.run_tests = true;