@@ -40,7 +40,7 @@ pub mod test {
4040 cli:: { parse_opts, TestOpts } ,
4141 filter_tests,
4242 helpers:: metrics:: { Metric , MetricMap } ,
43- options:: { Concurrent , Options , RunIgnored , RunStrategy , ShouldPanic } ,
43+ options:: { Options , RunIgnored , RunStrategy , ShouldPanic } ,
4444 run_test, test_main, test_main_static,
4545 test_result:: { TestResult , TrFailed , TrFailedMsg , TrIgnored , TrOk } ,
4646 time:: { TestExecTime , TestTimeOptions } ,
@@ -85,7 +85,7 @@ use event::{CompletedTest, TestEvent};
8585use helpers:: concurrency:: get_concurrency;
8686use helpers:: exit_code:: get_exit_code;
8787use helpers:: shuffle:: { get_shuffle_seed, shuffle_tests} ;
88- use options:: { Concurrent , RunStrategy } ;
88+ use options:: RunStrategy ;
8989use test_result:: * ;
9090use time:: TestExecTime ;
9191
@@ -235,6 +235,19 @@ where
235235 join_handle : Option < thread:: JoinHandle < ( ) > > ,
236236 }
237237
238+ impl RunningTest {
239+ fn join ( self , completed_test : & mut CompletedTest ) {
240+ if let Some ( join_handle) = self . join_handle {
241+ if let Err ( _) = join_handle. join ( ) {
242+ if let TrOk = completed_test. result {
243+ completed_test. result =
244+ TrFailedMsg ( "panicked after reporting success" . to_string ( ) ) ;
245+ }
246+ }
247+ }
248+ }
249+ }
250+
238251 // Use a deterministic hasher
239252 type TestMap =
240253 HashMap < TestId , RunningTest , BuildHasherDefault < collections:: hash_map:: DefaultHasher > > ;
@@ -328,10 +341,10 @@ where
328341 let ( id, test) = remaining. pop_front ( ) . unwrap ( ) ;
329342 let event = TestEvent :: TeWait ( test. desc . clone ( ) ) ;
330343 notify_about_test_event ( event) ?;
331- let join_handle =
332- run_test ( opts , !opts . run_tests , id , test, run_strategy , tx . clone ( ) , Concurrent :: No ) ;
333- assert ! ( join_handle . is_none ( ) ) ;
334- let completed_test = rx . recv ( ) . unwrap ( ) ;
344+ let join_handle = run_test ( opts , !opts . run_tests , id , test , run_strategy , tx . clone ( ) ) ;
345+ // Wait for the test to complete.
346+ let mut completed_test = rx . recv ( ) . unwrap ( ) ;
347+ RunningTest { join_handle } . join ( & mut completed_test ) ;
335348
336349 let event = TestEvent :: TeResult ( completed_test) ;
337350 notify_about_test_event ( event) ?;
@@ -345,15 +358,8 @@ where
345358
346359 let event = TestEvent :: TeWait ( desc. clone ( ) ) ;
347360 notify_about_test_event ( event) ?; //here no pad
348- let join_handle = run_test (
349- opts,
350- !opts. run_tests ,
351- id,
352- test,
353- run_strategy,
354- tx. clone ( ) ,
355- Concurrent :: Yes ,
356- ) ;
361+ let join_handle =
362+ run_test ( opts, !opts. run_tests , id, test, run_strategy, tx. clone ( ) ) ;
357363 running_tests. insert ( id, RunningTest { join_handle } ) ;
358364 timeout_queue. push_back ( TimeoutEntry { id, desc, timeout } ) ;
359365 pending += 1 ;
@@ -385,14 +391,7 @@ where
385391
386392 let mut completed_test = res. unwrap ( ) ;
387393 let running_test = running_tests. remove ( & completed_test. id ) . unwrap ( ) ;
388- if let Some ( join_handle) = running_test. join_handle {
389- if let Err ( _) = join_handle. join ( ) {
390- if let TrOk = completed_test. result {
391- completed_test. result =
392- TrFailedMsg ( "panicked after reporting success" . to_string ( ) ) ;
393- }
394- }
395- }
394+ running_test. join ( & mut completed_test) ;
396395
397396 let event = TestEvent :: TeResult ( completed_test) ;
398397 notify_about_test_event ( event) ?;
@@ -405,8 +404,10 @@ where
405404 for ( id, b) in filtered_benchs {
406405 let event = TestEvent :: TeWait ( b. desc . clone ( ) ) ;
407406 notify_about_test_event ( event) ?;
408- run_test ( opts, false , id, b, run_strategy, tx. clone ( ) , Concurrent :: No ) ;
409- let completed_test = rx. recv ( ) . unwrap ( ) ;
407+ let join_handle = run_test ( opts, false , id, b, run_strategy, tx. clone ( ) ) ;
408+ // Wait for the test to complete.
409+ let mut completed_test = rx. recv ( ) . unwrap ( ) ;
410+ RunningTest { join_handle } . join ( & mut completed_test) ;
410411
411412 let event = TestEvent :: TeResult ( completed_test) ;
412413 notify_about_test_event ( event) ?;
@@ -480,7 +481,6 @@ pub fn run_test(
480481 test : TestDescAndFn ,
481482 strategy : RunStrategy ,
482483 monitor_ch : Sender < CompletedTest > ,
483- concurrency : Concurrent ,
484484) -> Option < thread:: JoinHandle < ( ) > > {
485485 let TestDescAndFn { desc, testfn } = test;
486486
@@ -498,7 +498,6 @@ pub fn run_test(
498498 struct TestRunOpts {
499499 pub strategy : RunStrategy ,
500500 pub nocapture : bool ,
501- pub concurrency : Concurrent ,
502501 pub time : Option < time:: TestTimeOptions > ,
503502 }
504503
@@ -509,7 +508,6 @@ pub fn run_test(
509508 testfn : Box < dyn FnOnce ( ) -> Result < ( ) , String > + Send > ,
510509 opts : TestRunOpts ,
511510 ) -> Option < thread:: JoinHandle < ( ) > > {
512- let concurrency = opts. concurrency ;
513511 let name = desc. name . clone ( ) ;
514512
515513 let runtest = move || match opts. strategy {
@@ -536,7 +534,7 @@ pub fn run_test(
536534 // the test synchronously, regardless of the concurrency
537535 // level.
538536 let supports_threads = !cfg ! ( target_os = "emscripten" ) && !cfg ! ( target_family = "wasm" ) ;
539- if concurrency == Concurrent :: Yes && supports_threads {
537+ if supports_threads {
540538 let cfg = thread:: Builder :: new ( ) . name ( name. as_slice ( ) . to_owned ( ) ) ;
541539 let mut runtest = Arc :: new ( Mutex :: new ( Some ( runtest) ) ) ;
542540 let runtest2 = runtest. clone ( ) ;
@@ -557,7 +555,7 @@ pub fn run_test(
557555 }
558556
559557 let test_run_opts =
560- TestRunOpts { strategy, nocapture : opts. nocapture , concurrency , time : opts. time_options } ;
558+ TestRunOpts { strategy, nocapture : opts. nocapture , time : opts. time_options } ;
561559
562560 match testfn {
563561 DynBenchFn ( benchfn) => {
0 commit comments