@@ -54,7 +54,7 @@ pub mod test {
54
54
time:: { TestExecTime , TestTimeOptions } ,
55
55
types:: {
56
56
DynTestFn , DynTestName , StaticBenchFn , StaticTestFn , StaticTestName , TestDesc ,
57
- TestDescAndFn , TestName , TestType ,
57
+ TestDescAndFn , TestId , TestName , TestType ,
58
58
} ,
59
59
} ;
60
60
}
@@ -215,9 +215,10 @@ where
215
215
216
216
// Use a deterministic hasher
217
217
type TestMap =
218
- HashMap < TestDesc , RunningTest , BuildHasherDefault < collections:: hash_map:: DefaultHasher > > ;
218
+ HashMap < TestId , RunningTest , BuildHasherDefault < collections:: hash_map:: DefaultHasher > > ;
219
219
220
220
struct TimeoutEntry {
221
+ id : TestId ,
221
222
desc : TestDesc ,
222
223
timeout : Instant ,
223
224
}
@@ -249,7 +250,9 @@ where
249
250
250
251
let ( filtered_tests, filtered_benchs) : ( Vec < _ > , _ ) = filtered_tests
251
252
. into_iter ( )
252
- . partition ( |e| matches ! ( e. testfn, StaticTestFn ( _) | DynTestFn ( _) ) ) ;
253
+ . enumerate ( )
254
+ . map ( |( i, e) | ( TestId ( i) , e) )
255
+ . partition ( |( _, e) | matches ! ( e. testfn, StaticTestFn ( _) | DynTestFn ( _) ) ) ;
253
256
254
257
let concurrency = opts. test_threads . unwrap_or_else ( get_concurrency) ;
255
258
@@ -278,7 +281,7 @@ where
278
281
break ;
279
282
}
280
283
let timeout_entry = timeout_queue. pop_front ( ) . unwrap ( ) ;
281
- if running_tests. contains_key ( & timeout_entry. desc ) {
284
+ if running_tests. contains_key ( & timeout_entry. id ) {
282
285
timed_out. push ( timeout_entry. desc ) ;
283
286
}
284
287
}
@@ -294,11 +297,11 @@ where
294
297
295
298
if concurrency == 1 {
296
299
while !remaining. is_empty ( ) {
297
- let test = remaining. pop ( ) . unwrap ( ) ;
300
+ let ( id , test) = remaining. pop ( ) . unwrap ( ) ;
298
301
let event = TestEvent :: TeWait ( test. desc . clone ( ) ) ;
299
302
notify_about_test_event ( event) ?;
300
303
let join_handle =
301
- run_test ( opts, !opts. run_tests , test, run_strategy, tx. clone ( ) , Concurrent :: No ) ;
304
+ run_test ( opts, !opts. run_tests , id , test, run_strategy, tx. clone ( ) , Concurrent :: No ) ;
302
305
assert ! ( join_handle. is_none( ) ) ;
303
306
let completed_test = rx. recv ( ) . unwrap ( ) ;
304
307
@@ -308,7 +311,7 @@ where
308
311
} else {
309
312
while pending > 0 || !remaining. is_empty ( ) {
310
313
while pending < concurrency && !remaining. is_empty ( ) {
311
- let test = remaining. pop ( ) . unwrap ( ) ;
314
+ let ( id , test) = remaining. pop ( ) . unwrap ( ) ;
312
315
let timeout = time:: get_default_test_timeout ( ) ;
313
316
let desc = test. desc . clone ( ) ;
314
317
@@ -317,13 +320,14 @@ where
317
320
let join_handle = run_test (
318
321
opts,
319
322
!opts. run_tests ,
323
+ id,
320
324
test,
321
325
run_strategy,
322
326
tx. clone ( ) ,
323
327
Concurrent :: Yes ,
324
328
) ;
325
- running_tests. insert ( desc . clone ( ) , RunningTest { join_handle } ) ;
326
- timeout_queue. push_back ( TimeoutEntry { desc, timeout } ) ;
329
+ running_tests. insert ( id , RunningTest { join_handle } ) ;
330
+ timeout_queue. push_back ( TimeoutEntry { id , desc, timeout } ) ;
327
331
pending += 1 ;
328
332
}
329
333
@@ -352,13 +356,12 @@ where
352
356
}
353
357
354
358
let mut completed_test = res. unwrap ( ) ;
355
- if let Some ( running_test) = running_tests. remove ( & completed_test. desc ) {
356
- if let Some ( join_handle) = running_test. join_handle {
357
- if let Err ( _) = join_handle. join ( ) {
358
- if let TrOk = completed_test. result {
359
- completed_test. result =
360
- TrFailedMsg ( "panicked after reporting success" . to_string ( ) ) ;
361
- }
359
+ let running_test = running_tests. remove ( & completed_test. id ) . unwrap ( ) ;
360
+ if let Some ( join_handle) = running_test. join_handle {
361
+ if let Err ( _) = join_handle. join ( ) {
362
+ if let TrOk = completed_test. result {
363
+ completed_test. result =
364
+ TrFailedMsg ( "panicked after reporting success" . to_string ( ) ) ;
362
365
}
363
366
}
364
367
}
@@ -371,10 +374,10 @@ where
371
374
372
375
if opts. bench_benchmarks {
373
376
// All benchmarks run at the end, in serial.
374
- for b in filtered_benchs {
377
+ for ( id , b ) in filtered_benchs {
375
378
let event = TestEvent :: TeWait ( b. desc . clone ( ) ) ;
376
379
notify_about_test_event ( event) ?;
377
- run_test ( opts, false , b, run_strategy, tx. clone ( ) , Concurrent :: No ) ;
380
+ run_test ( opts, false , id , b, run_strategy, tx. clone ( ) , Concurrent :: No ) ;
378
381
let completed_test = rx. recv ( ) . unwrap ( ) ;
379
382
380
383
let event = TestEvent :: TeResult ( completed_test) ;
@@ -448,6 +451,7 @@ pub fn convert_benchmarks_to_tests(tests: Vec<TestDescAndFn>) -> Vec<TestDescAnd
448
451
pub fn run_test (
449
452
opts : & TestOpts ,
450
453
force_ignore : bool ,
454
+ id : TestId ,
451
455
test : TestDescAndFn ,
452
456
strategy : RunStrategy ,
453
457
monitor_ch : Sender < CompletedTest > ,
@@ -461,7 +465,7 @@ pub fn run_test(
461
465
&& !cfg ! ( target_os = "emscripten" ) ;
462
466
463
467
if force_ignore || desc. ignore || ignore_because_no_process_support {
464
- let message = CompletedTest :: new ( desc, TrIgnored , None , Vec :: new ( ) ) ;
468
+ let message = CompletedTest :: new ( id , desc, TrIgnored , None , Vec :: new ( ) ) ;
465
469
monitor_ch. send ( message) . unwrap ( ) ;
466
470
return None ;
467
471
}
@@ -474,6 +478,7 @@ pub fn run_test(
474
478
}
475
479
476
480
fn run_test_inner (
481
+ id : TestId ,
477
482
desc : TestDesc ,
478
483
monitor_ch : Sender < CompletedTest > ,
479
484
testfn : Box < dyn FnOnce ( ) + Send > ,
@@ -484,6 +489,7 @@ pub fn run_test(
484
489
485
490
let runtest = move || match opts. strategy {
486
491
RunStrategy :: InProcess => run_test_in_process (
492
+ id,
487
493
desc,
488
494
opts. nocapture ,
489
495
opts. time . is_some ( ) ,
@@ -492,6 +498,7 @@ pub fn run_test(
492
498
opts. time ,
493
499
) ,
494
500
RunStrategy :: SpawnPrimary => spawn_test_subprocess (
501
+ id,
495
502
desc,
496
503
opts. nocapture ,
497
504
opts. time . is_some ( ) ,
@@ -530,14 +537,14 @@ pub fn run_test(
530
537
match testfn {
531
538
DynBenchFn ( bencher) => {
532
539
// Benchmarks aren't expected to panic, so we run them all in-process.
533
- crate :: bench:: benchmark ( desc, monitor_ch, opts. nocapture , |harness| {
540
+ crate :: bench:: benchmark ( id , desc, monitor_ch, opts. nocapture , |harness| {
534
541
bencher. run ( harness)
535
542
} ) ;
536
543
None
537
544
}
538
545
StaticBenchFn ( benchfn) => {
539
546
// Benchmarks aren't expected to panic, so we run them all in-process.
540
- crate :: bench:: benchmark ( desc, monitor_ch, opts. nocapture , benchfn) ;
547
+ crate :: bench:: benchmark ( id , desc, monitor_ch, opts. nocapture , benchfn) ;
541
548
None
542
549
}
543
550
DynTestFn ( f) => {
@@ -546,13 +553,15 @@ pub fn run_test(
546
553
_ => panic ! ( "Cannot run dynamic test fn out-of-process" ) ,
547
554
} ;
548
555
run_test_inner (
556
+ id,
549
557
desc,
550
558
monitor_ch,
551
559
Box :: new ( move || __rust_begin_short_backtrace ( f) ) ,
552
560
test_run_opts,
553
561
)
554
562
}
555
563
StaticTestFn ( f) => run_test_inner (
564
+ id,
556
565
desc,
557
566
monitor_ch,
558
567
Box :: new ( move || __rust_begin_short_backtrace ( f) ) ,
@@ -571,6 +580,7 @@ fn __rust_begin_short_backtrace<F: FnOnce()>(f: F) {
571
580
}
572
581
573
582
fn run_test_in_process (
583
+ id : TestId ,
574
584
desc : TestDesc ,
575
585
nocapture : bool ,
576
586
report_time : bool ,
@@ -599,11 +609,12 @@ fn run_test_in_process(
599
609
Err ( e) => calc_result ( & desc, Err ( e. as_ref ( ) ) , & time_opts, & exec_time) ,
600
610
} ;
601
611
let stdout = data. lock ( ) . unwrap_or_else ( |e| e. into_inner ( ) ) . to_vec ( ) ;
602
- let message = CompletedTest :: new ( desc, test_result, exec_time, stdout) ;
612
+ let message = CompletedTest :: new ( id , desc, test_result, exec_time, stdout) ;
603
613
monitor_ch. send ( message) . unwrap ( ) ;
604
614
}
605
615
606
616
fn spawn_test_subprocess (
617
+ id : TestId ,
607
618
desc : TestDesc ,
608
619
nocapture : bool ,
609
620
report_time : bool ,
@@ -653,7 +664,7 @@ fn spawn_test_subprocess(
653
664
( result, test_output, exec_time)
654
665
} ) ( ) ;
655
666
656
- let message = CompletedTest :: new ( desc, result, exec_time, test_output) ;
667
+ let message = CompletedTest :: new ( id , desc, result, exec_time, test_output) ;
657
668
monitor_ch. send ( message) . unwrap ( ) ;
658
669
}
659
670
0 commit comments