@@ -369,6 +369,7 @@ function retest(args::Union{Module,AbstractString,Regex}...;
369
369
nprinted = 0
370
370
allpass = true
371
371
exception = Ref {Exception} ()
372
+ interrupted = Threads. Atomic {Bool} (false )
372
373
373
374
module_ts = Testset. ReTestSet (" " , string (mod) * ' :' , true )
374
375
push! (root. results, module_ts)
@@ -409,13 +410,13 @@ function retest(args::Union{Module,AbstractString,Regex}...;
409
410
end
410
411
411
412
previewer = previewchan === nothing ? nothing :
412
- @async begin
413
+ @async try
413
414
timer = [' |' , ' /' , ' -' , ' \\ ' ]
414
415
cursor = 0
415
416
desc = " "
416
417
finito = false
417
418
418
- while ! finito
419
+ while ! finito && ! interrupted[]
419
420
lock (printlock) do
420
421
newdesc = take_latest! (previewchan)
421
422
if newdesc === nothing
@@ -465,7 +466,17 @@ function retest(args::Union{Module,AbstractString,Regex}...;
465
466
end
466
467
sleep (0.13 )
467
468
end
468
- end
469
+ catch ex
470
+ # TODO : clarify what is the correct thing to do here
471
+ if ex isa InterruptException
472
+ interrupted[] = true
473
+ rethrow ()
474
+ else
475
+ # then there is probably a bug in the previewer code, but it might be fine
476
+ # for the worker/printer to continue?
477
+ rethrow ()
478
+ end
479
+ end # previewer task
469
480
470
481
# TODO : move printer task out of worker?
471
482
worker = @task begin
@@ -493,7 +504,7 @@ function retest(args::Union{Module,AbstractString,Regex}...;
493
504
align_overflow = 0
494
505
end
495
506
496
- while ! finito
507
+ while ! finito && ! interrupted[]
497
508
rts = take! (outchan)
498
509
lock (printlock) do
499
510
if previewchan != = nothing
@@ -538,7 +549,7 @@ function retest(args::Union{Module,AbstractString,Regex}...;
538
549
end
539
550
end
540
551
end
541
- end
552
+ end # printer task
542
553
543
554
ndone = 0
544
555
@@ -553,15 +564,14 @@ function retest(args::Union{Module,AbstractString,Regex}...;
553
564
@async put! (computechan, nothing )
554
565
end
555
566
556
-
557
567
@sync for wrkr in workers ()
558
568
@async begin
559
569
if nprocs () == 1
560
570
take! (computechan)
561
571
end
562
572
file = nothing
563
573
idx = 0
564
- while ndone < length (tests)
574
+ while ndone < length (tests) && ! interrupted[]
565
575
ndone += 1
566
576
if ! @isdefined (groups)
567
577
ts = tests[ndone]
@@ -600,19 +610,12 @@ function retest(args::Union{Module,AbstractString,Regex}...;
600
610
put! (previewchan, desc)
601
611
end
602
612
603
- resp = try
604
- chan = (out= outchan, compute= computechan, preview= previewchan)
605
- remotecall_fetch (wrkr, mod, ts, regex, chan
613
+ chan = (out= outchan, compute= computechan, preview= previewchan)
614
+ resp = remotecall_fetch (wrkr, mod, ts, regex, chan
606
615
) do mod, ts, regex, chan
607
616
mts = make_ts (ts, regex, format. stats, chan)
608
617
Core. eval (mod, mts)
609
618
end
610
- catch e
611
- allpass = false
612
- ndone = length (tests)
613
- isa (e, InterruptException) || rethrow ()
614
- return
615
- end
616
619
if resp isa Vector
617
620
ntests += length (resp)
618
621
append! (module_ts. results, resp)
@@ -622,29 +625,38 @@ function retest(args::Union{Module,AbstractString,Regex}...;
622
625
end
623
626
624
627
end
625
- end
626
- end
628
+ end # wrkr: @async
629
+ end # @sync for wrkr...
627
630
631
+ # TODO : maybe put the following stuff in a finally clause where we schedule worker
632
+ # (as part of the mechanism to handle exceptions vs interrupt[])
628
633
put! (outchan, nothing )
629
634
previewchan != = nothing &&
630
635
put! (previewchan, nothing )
631
636
wait (printer)
632
- end
637
+ end # worker = @task begin ...
633
638
634
- if previewchan != = nothing # then nthreads() > 1
635
- # we try to keep thread #1 free of heavy work, so that the previewer stays
636
- # responsive
637
- tid = rand (2 : nthreads ())
638
- thread_pin (worker, UInt16 (tid))
639
- else
640
- schedule (worker)
641
- end
639
+ try
640
+ if previewchan != = nothing # then nthreads() > 1
641
+ # we try to keep thread #1 free of heavy work, so that the previewer stays
642
+ # responsive
643
+ tid = rand (2 : nthreads ())
644
+ thread_pin (worker, UInt16 (tid))
645
+ else
646
+ schedule (worker)
647
+ end
642
648
643
- wait (worker)
644
- previewer != = nothing &&
645
- wait (previewer)
649
+ wait (worker)
650
+ previewer != = nothing &&
651
+ wait (previewer)
652
+
653
+ catch ex
654
+ interrupted[] = true
655
+ ex isa InterruptException ||
656
+ rethrow ()
657
+ end
646
658
647
- @assert ! allpass || nprinted == ntests
659
+ @assert interrupted[] || ! allpass || nprinted == ntests
648
660
if isassigned (exception)
649
661
throw (exception[])
650
662
end
0 commit comments