Repository: JuliaLang/julia
File: test/runtests.jl (Julia)

Code before:
                catch e
                    isa(e, InterruptException) || rethrow()
                finally
                    REPL.Terminals.raw!(term, false)
                end
            end
        end
        o_ts_duration = @elapsed Experimental.@sync begin
            for p in workers()
                @async begin
                    push!(all_tasks, current_task())
                    while length(tests) > 0
                        test = popfirst!(tests)
                        running_tests[test] = now()
                        wrkr = p

                        # Create a timer for this test to report long-running status
                        test_timers[test] = Timer(longrunning_delay, interval=longrunning_interval) do timer
                            if haskey(running_tests, test)  # Check test is still running
                                start_time = running_tests[test]
                                elapsed = now() - start_time
                                elapsed_minutes = elapsed.value ÷ (1000 * 60)

                                elapsed_str = if elapsed_minutes >= 60
                                    hours = elapsed_minutes ÷ 60
                                    mins = elapsed_minutes % 60
                                    "$(hours)h $(mins)m"
                                else
                                    "$(elapsed_minutes)m"
                                end

                                @lock print_lock begin
                                    print(test)
                                    print(lpad("($(wrkr))", name_align - textwidth(test) + 1, " "), " | ")
                                    # Calculate total width of data columns: "Time (s) | GC (s) | GC % | Alloc (MB) | RSS (MB)"
                                    # This is: elapsed_align + 3 + gc_align + 3 + percent_align + 3 + alloc_align + 3 + rss_align
                                    data_width = elapsed_align + gc_align + percent_align + alloc_align + rss_align + 12  # 12 = 4 * " | "
                                    message = "has been running for $(elapsed_str)"
                                    centered_message = lpad(rpad(message, (data_width + textwidth(message)) ÷ 2), data_width)
                                    printstyled(centered_message, "\n", color=:light_black)
                                end
                            end
                        end
                        before = time()
                        resp, duration = try
                                r = remotecall_fetch(@Base.world(runtests, ∞), wrkr, test, test_path(test); seed=seed)
                                r, time() - before
                            catch e
                                isa(e, InterruptException) && return
                                Any[CapturedException(e, catch_backtrace())], time() - before
                            end

Review comment (refactor):
Could simplify a tiny bit as
```suggestion
                                    hours, mins = divrem(elapsed_minutes, 60)
```

Code after:
            for p in workers()
                @async begin
                    push!(all_tasks, current_task())
                    while length(tests) > 0
                        test = popfirst!(tests)
                        running_tests[test] = now()
                        wrkr = p

                        # Create a timer for this test to report long-running status
                        test_timers[test] = Timer(longrunning_delay, interval=longrunning_interval) do timer
                            if haskey(running_tests, test)  # Check test is still running
                                start_time = running_tests[test]
                                elapsed = now() - start_time
                                elapsed_minutes = elapsed.value ÷ (1000 * 60)

                                elapsed_str = if elapsed_minutes >= 60
                                    hours, mins = divrem(elapsed_minutes, 60)
                                    "$(hours)h $(mins)m"
                                else
                                    "$(elapsed_minutes)m"
                                end

                                @lock print_lock begin
                                    print(test)
                                    print(lpad("($(wrkr))", name_align - textwidth(test) + 1, " "), " | ")
                                    # Calculate total width of data columns: "Time (s) | GC (s) | GC % | Alloc (MB) | RSS (MB)"
                                    # This is: elapsed_align + 3 + gc_align + 3 + percent_align + 3 + alloc_align + 3 + rss_align
                                    data_width = elapsed_align + gc_align + percent_align + alloc_align + rss_align + 12  # 12 = 4 * " | "
                                    message = "has been running for $(elapsed_str)"
                                    centered_message = lpad(rpad(message, (data_width + textwidth(message)) ÷ 2), data_width)
                                    printstyled(centered_message, "\n", color=:light_black)
                                end
                            end
                        end
                        before = time()
                        resp, duration = try
                                r = remotecall_fetch(@Base.world(runtests, ∞), wrkr, test, test_path(test); seed=seed)
                                r, time() - before
                            catch e
                                isa(e, InterruptException) && return
                                Any[CapturedException(e, catch_backtrace())], time() - before
                            end
                        delete!(running_tests, test)
                        if haskey(test_timers, test)
                            close(test_timers[test])
                            delete!(test_timers, test)
                        end
                        push!(results, (test, resp, duration))
                        if length(resp) == 1
                            print_testworker_errored(test, wrkr, exit_on_error ? nothing : resp[1])
                            if exit_on_error