@@ -40,7 +40,7 @@ pub mod test {
40
40
cli:: { parse_opts, TestOpts } ,
41
41
filter_tests,
42
42
helpers:: metrics:: { Metric , MetricMap } ,
43
- options:: { Concurrent , Options , RunIgnored , RunStrategy , ShouldPanic } ,
43
+ options:: { Options , RunIgnored , RunStrategy , ShouldPanic } ,
44
44
run_test, test_main, test_main_static,
45
45
test_result:: { TestResult , TrFailed , TrFailedMsg , TrIgnored , TrOk } ,
46
46
time:: { TestExecTime , TestTimeOptions } ,
@@ -85,7 +85,7 @@ use event::{CompletedTest, TestEvent};
85
85
use helpers:: concurrency:: get_concurrency;
86
86
use helpers:: exit_code:: get_exit_code;
87
87
use helpers:: shuffle:: { get_shuffle_seed, shuffle_tests} ;
88
- use options:: { Concurrent , RunStrategy } ;
88
+ use options:: RunStrategy ;
89
89
use test_result:: * ;
90
90
use time:: TestExecTime ;
91
91
@@ -267,6 +267,19 @@ where
267
267
join_handle : Option < thread:: JoinHandle < ( ) > > ,
268
268
}
269
269
270
+ impl RunningTest {
271
+ fn join ( self , completed_test : & mut CompletedTest ) {
272
+ if let Some ( join_handle) = self . join_handle {
273
+ if let Err ( _) = join_handle. join ( ) {
274
+ if let TrOk = completed_test. result {
275
+ completed_test. result =
276
+ TrFailedMsg ( "panicked after reporting success" . to_string ( ) ) ;
277
+ }
278
+ }
279
+ }
280
+ }
281
+ }
282
+
270
283
// Use a deterministic hasher
271
284
type TestMap =
272
285
HashMap < TestId , RunningTest , BuildHasherDefault < collections:: hash_map:: DefaultHasher > > ;
@@ -366,10 +379,10 @@ where
366
379
let ( id, test) = remaining. pop_front ( ) . unwrap ( ) ;
367
380
let event = TestEvent :: TeWait ( test. desc . clone ( ) ) ;
368
381
notify_about_test_event ( event) ?;
369
- let join_handle =
370
- run_test ( opts , !opts . run_tests , id , test, run_strategy , tx . clone ( ) , Concurrent :: No ) ;
371
- assert ! ( join_handle . is_none ( ) ) ;
372
- let completed_test = rx . recv ( ) . unwrap ( ) ;
382
+ let join_handle = run_test ( opts , !opts . run_tests , id , test , run_strategy , tx . clone ( ) ) ;
383
+ // Wait for the test to complete.
384
+ let mut completed_test = rx . recv ( ) . unwrap ( ) ;
385
+ RunningTest { join_handle } . join ( & mut completed_test ) ;
373
386
374
387
let event = TestEvent :: TeResult ( completed_test) ;
375
388
notify_about_test_event ( event) ?;
@@ -383,15 +396,8 @@ where
383
396
384
397
let event = TestEvent :: TeWait ( desc. clone ( ) ) ;
385
398
notify_about_test_event ( event) ?; //here no pad
386
- let join_handle = run_test (
387
- opts,
388
- !opts. run_tests ,
389
- id,
390
- test,
391
- run_strategy,
392
- tx. clone ( ) ,
393
- Concurrent :: Yes ,
394
- ) ;
399
+ let join_handle =
400
+ run_test ( opts, !opts. run_tests , id, test, run_strategy, tx. clone ( ) ) ;
395
401
running_tests. insert ( id, RunningTest { join_handle } ) ;
396
402
timeout_queue. push_back ( TimeoutEntry { id, desc, timeout } ) ;
397
403
pending += 1 ;
@@ -423,14 +429,7 @@ where
423
429
424
430
let mut completed_test = res. unwrap ( ) ;
425
431
let running_test = running_tests. remove ( & completed_test. id ) . unwrap ( ) ;
426
- if let Some ( join_handle) = running_test. join_handle {
427
- if let Err ( _) = join_handle. join ( ) {
428
- if let TrOk = completed_test. result {
429
- completed_test. result =
430
- TrFailedMsg ( "panicked after reporting success" . to_string ( ) ) ;
431
- }
432
- }
433
- }
432
+ running_test. join ( & mut completed_test) ;
434
433
435
434
let event = TestEvent :: TeResult ( completed_test) ;
436
435
notify_about_test_event ( event) ?;
@@ -443,8 +442,10 @@ where
443
442
for ( id, b) in filtered. benchs {
444
443
let event = TestEvent :: TeWait ( b. desc . clone ( ) ) ;
445
444
notify_about_test_event ( event) ?;
446
- run_test ( opts, false , id, b, run_strategy, tx. clone ( ) , Concurrent :: No ) ;
447
- let completed_test = rx. recv ( ) . unwrap ( ) ;
445
+ let join_handle = run_test ( opts, false , id, b, run_strategy, tx. clone ( ) ) ;
446
+ // Wait for the test to complete.
447
+ let mut completed_test = rx. recv ( ) . unwrap ( ) ;
448
+ RunningTest { join_handle } . join ( & mut completed_test) ;
448
449
449
450
let event = TestEvent :: TeResult ( completed_test) ;
450
451
notify_about_test_event ( event) ?;
@@ -520,7 +521,6 @@ pub fn run_test(
520
521
test : TestDescAndFn ,
521
522
strategy : RunStrategy ,
522
523
monitor_ch : Sender < CompletedTest > ,
523
- concurrency : Concurrent ,
524
524
) -> Option < thread:: JoinHandle < ( ) > > {
525
525
let TestDescAndFn { desc, testfn } = test;
526
526
@@ -538,7 +538,6 @@ pub fn run_test(
538
538
struct TestRunOpts {
539
539
pub strategy : RunStrategy ,
540
540
pub nocapture : bool ,
541
- pub concurrency : Concurrent ,
542
541
pub time : Option < time:: TestTimeOptions > ,
543
542
}
544
543
@@ -549,7 +548,6 @@ pub fn run_test(
549
548
testfn : Box < dyn FnOnce ( ) -> Result < ( ) , String > + Send > ,
550
549
opts : TestRunOpts ,
551
550
) -> Option < thread:: JoinHandle < ( ) > > {
552
- let concurrency = opts. concurrency ;
553
551
let name = desc. name . clone ( ) ;
554
552
555
553
let runtest = move || match opts. strategy {
@@ -576,7 +574,7 @@ pub fn run_test(
576
574
// the test synchronously, regardless of the concurrency
577
575
// level.
578
576
let supports_threads = !cfg ! ( target_os = "emscripten" ) && !cfg ! ( target_family = "wasm" ) ;
579
- if concurrency == Concurrent :: Yes && supports_threads {
577
+ if supports_threads {
580
578
let cfg = thread:: Builder :: new ( ) . name ( name. as_slice ( ) . to_owned ( ) ) ;
581
579
let mut runtest = Arc :: new ( Mutex :: new ( Some ( runtest) ) ) ;
582
580
let runtest2 = runtest. clone ( ) ;
@@ -597,7 +595,7 @@ pub fn run_test(
597
595
}
598
596
599
597
let test_run_opts =
600
- TestRunOpts { strategy, nocapture : opts. nocapture , concurrency , time : opts. time_options } ;
598
+ TestRunOpts { strategy, nocapture : opts. nocapture , time : opts. time_options } ;
601
599
602
600
match testfn {
603
601
DynBenchFn ( benchfn) => {
0 commit comments