@@ -6,6 +6,7 @@ using Distributed
66using Dates
77using Printf: @sprintf
88using Base. Filesystem: path_separator
9+ using Statistics
910import Test
1011import Random
1112import IOCapture
@@ -416,9 +417,9 @@ function runtests(ARGS; testfilter = Returns(true), RecordType = TestRecord,
416417 end
417418 end
418419 end
419- sort! (tests; by = (file) -> stat (joinpath (WORKDIR, file * " .jl" )). size, rev = true )
420420 # # finalize
421421 unique! (tests)
422+ Random. shuffle! (tests)
422423
423424 # list tests, if requested
424425 if do_list
@@ -443,9 +444,8 @@ function runtests(ARGS; testfilter = Returns(true), RecordType = TestRecord,
443444 if ! set_jobs
444445 jobs = default_njobs ()
445446 end
447+ jobs = clamp (jobs, 1 , length (tests))
446448 println (stdout , " Running $jobs tests in parallel. If this is too many, specify the `--jobs=N` argument to the tests, or set the `JULIA_CPU_THREADS` environment variable." )
447-
448- # add workers
449449 addworkers (min (jobs, length (tests)))
450450
451451 t0 = time ()
@@ -532,11 +532,23 @@ function runtests(ARGS; testfilter = Returns(true), RecordType = TestRecord,
532532 # line 3: progress + ETA
533533 line3 = " Progress: $completed /$total tests completed"
534534 if completed > 0
535- elapsed_so_far = time () - t0
536- avg_time_per_test = elapsed_so_far / completed
537- remaining_tests = length (tests) + length (running_tests)
538- eta_seconds = avg_time_per_test * remaining_tests
539- eta_mins = round (Int, eta_seconds / 60 )
535+ # gather stats
536+ durations_done = [end_time - start_time for (_, _, start_time, end_time) in results]
537+ durations_running = [time () - start_time for (_, start_time) in values (running_tests)]
538+ n_done = length (durations_done)
539+ n_running = length (durations_running)
540+ n_remaining = length (tests)
541+ n_total = n_done + n_running + n_remaining
542+
543+ # estimate per-test time (slightly pessimistic)
544+ μ = mean (durations_done)
545+ σ = length (durations_done) > 1 ? std (durations_done) : 0.0
546+ est_per_test = μ + 0.5 σ
547+
548+ # estimate remaining time
549+ est_remaining = sum (durations_running) + n_remaining * est_per_test
550+ eta_sec = est_remaining / jobs
551+ eta_mins = round (Int, eta_sec / 60 )
540552 line3 *= " | ETA: ~$eta_mins min"
541553 end
542554
0 commit comments