Skip to content

Commit ea5e43c

Browse files
committed
Add a Configuration object for more control over test set-up.
1 parent 577220d commit ea5e43c

File tree

1 file changed

+55
-35
lines changed

1 file changed

+55
-35
lines changed

src/run.jl

+55-35
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export Configuration
2+
13
function prepare_runner()
24
for runner in ("ubuntu", "arch")
35
cd(joinpath(dirname(@__DIR__), "runner.$runner")) do
@@ -460,26 +462,34 @@ function kill_container(container)
460462
Base.run(cmd)
461463
end
462464

463-
function run(julia_versions::Vector{VersionNumber}, pkgs::Vector;
465+
struct Configuration
466+
julia::VersionNumber
467+
compiled::Bool
468+
# TODO: depwarn, checkbounds, etc
469+
end
470+
471+
Configuration(julia::VersionNumber) = new(julia, false)
472+
473+
function run(configs::Vector{Configuration}, pkgs::Vector;
464474
ninstances::Integer=Sys.CPU_THREADS, retries::Integer=2, kwargs...)
465475
# here we deal with managing execution: spawning workers, output, result I/O, etc
466476

467477
prepare_runner()
468478

469479
# Julia installation and local cache
470-
julia_environments = Dict{VersionNumber,Tuple{String,String}}()
471-
for julia in julia_versions
472-
install = prepare_julia(julia)
480+
instantiated_configs = Dict{Configuration,Tuple{String,String}}()
481+
for config in configs
482+
install = prepare_julia(config.julia)
473483
cache = mktempdir()
474-
julia_environments[julia] = (install, cache)
484+
instantiated_configs[config] = (install, cache)
475485
end
476486

477487
# global storage
478488
storage = storage_dir()
479489
mkpath(storage)
480490

481491
# make sure data is writable
482-
for (julia, (install,cache)) in julia_environments
492+
for (config, (install,cache)) in instantiated_configs
483493
Base.run(```docker run --mount type=bind,source=$storage,target=/storage
484494
--mount type=bind,source=$cache,target=/cache
485495
newpkgeval:ubuntu
@@ -501,16 +511,14 @@ function run(julia_versions::Vector{VersionNumber}, pkgs::Vector;
501511
JSON.parse(body)
502512
end
503513

504-
jobs = [(julia=julia, install=install, cache=cache,
505-
pkg=pkg) for (julia,(install,cache)) in julia_environments
506-
for pkg in pkgs]
514+
jobs = vec(collect(Iterators.product(instantiated_configs, pkgs)))
507515

508516
# use a random test order to (hopefully) get a more reasonable ETA
509517
shuffle!(jobs)
510518

511519
njobs = length(jobs)
512520
ninstances = min(njobs, ninstances)
513-
running = Vector{Union{Nothing, eltype(jobs)}}(nothing, ninstances)
521+
running = Vector{Any}(nothing, ninstances)
514522
times = DateTime[now() for i = 1:ninstances]
515523
all_workers = Task[]
516524

@@ -572,7 +580,8 @@ function run(julia_versions::Vector{VersionNumber}, pkgs::Vector;
572580
str = if job === nothing
573581
" #$i: -------"
574582
else
575-
" #$i: $(job.pkg.name) @ $(job.julia) ($(runtimestr(times[i])))"
583+
config, pkg = job
584+
" #$i: $(pkg.name) @ $(config.julia) ($(runtimestr(times[i])))"
576585
end
577586
if i%2 == 1 && i < ninstances
578587
print(io, rpad(str, 50))
@@ -590,6 +599,7 @@ function run(julia_versions::Vector{VersionNumber}, pkgs::Vector;
590599
end
591600

592601
result = DataFrame(julia = VersionNumber[],
602+
compiled = Bool[],
593603
name = String[],
594604
uuid = UUID[],
595605
version = Union{Missing,VersionNumber}[],
@@ -612,44 +622,45 @@ function run(julia_versions::Vector{VersionNumber}, pkgs::Vector;
612622
end
613623

614624
# Workers
625+
# TODO: we don't want to do this for both. but rather one of the builds is compiled, the other not...
615626
try @sync begin
616627
for i = 1:ninstances
617628
push!(all_workers, @async begin
618629
try
619630
while !isempty(jobs) && !done
620-
job = pop!(jobs)
631+
(config, (install, cache)), pkg = pop!(jobs)
621632
times[i] = now()
622-
running[i] = job
633+
running[i] = (config, pkg)
623634

624635
# can we even test this package?
625636
julia_supported = Dict{VersionNumber,Bool}()
626637
if VERSION >= v"1.5"
627638
ctx = Pkg.Types.Context()
628-
pkg_version_info = Pkg.Operations.load_versions(ctx, job.pkg.path)
639+
pkg_version_info = Pkg.Operations.load_versions(ctx, pkg.path)
629640
pkg_versions = sort!(collect(keys(pkg_version_info)))
630641
pkg_compat =
631642
Pkg.Operations.load_package_data(Pkg.Types.VersionSpec,
632-
joinpath(job.pkg.path,
643+
joinpath(pkg.path,
633644
"Compat.toml"),
634645
pkg_versions)
635646
for (pkg_version, bounds) in pkg_compat
636647
if haskey(bounds, "julia")
637648
julia_supported[pkg_version] =
638-
job.julia bounds["julia"]
649+
config.julia bounds["julia"]
639650
end
640651
end
641652
else
642-
pkg_version_info = Pkg.Operations.load_versions(job.pkg.path)
653+
pkg_version_info = Pkg.Operations.load_versions(pkg.path)
643654
pkg_compat =
644655
Pkg.Operations.load_package_data_raw(Pkg.Types.VersionSpec,
645-
joinpath(job.pkg.path,
656+
joinpath(pkg.path,
646657
"Compat.toml"))
647658
for (version_range, bounds) in pkg_compat
648659
if haskey(bounds, "julia")
649660
for pkg_version in keys(pkg_version_info)
650661
if pkg_version in version_range
651662
julia_supported[pkg_version] =
652-
job.julia bounds["julia"]
663+
config.julia bounds["julia"]
653664
end
654665
end
655666
end
@@ -663,37 +674,43 @@ function run(julia_versions::Vector{VersionNumber}, pkgs::Vector;
663674
supported = any(values(julia_supported))
664675
end
665676
if !supported
666-
push!(result, [job.julia, job.pkg.name, job.pkg.uuid, missing,
677+
push!(result, [config.julia, config.compiled,
678+
pkg.name, pkg.uuid, missing,
667679
:skip, :unsupported, 0, missing])
668680
continue
669-
elseif job.pkg.name in skip_lists[job.pkg.registry]
670-
push!(result, [job.julia, job.pkg.name, job.pkg.uuid, missing,
681+
elseif pkg.name in skip_lists[pkg.registry]
682+
push!(result, [config.julia, config.compiled,
683+
pkg.name, pkg.uuid, missing,
671684
:skip, :explicit, 0, missing])
672685
continue
673-
elseif endswith(job.pkg.name, "_jll")
674-
push!(result, [job.julia, job.pkg.name, job.pkg.uuid, missing,
686+
elseif endswith(pkg.name, "_jll")
687+
push!(result, [config.julia, config.compiled,
688+
pkg.name, pkg.uuid, missing,
675689
:skip, :jll, 0, missing])
676690
continue
677691
end
678692

693+
runner = config.compiled ? run_compiled_test : run_sandboxed_test
694+
679695
# perform an initial run
680696
pkg_version, status, reason, log =
681-
run_sandboxed_test(job.install, job.pkg; cache=job.cache,
682-
storage=storage, cpus=[i-1], kwargs...)
697+
runner(install, pkg; cache=cache,
698+
storage=storage, cpus=[i-1], kwargs...)
683699

684700
# certain packages are known to have flaky tests; retry them
685701
for j in 1:retries
686702
if status == :fail && reason == :test_failures &&
687-
job.pkg.name in retry_lists[job.pkg.registry]
703+
pkg.name in retry_lists[pkg.registry]
688704
times[i] = now()
689705
pkg_version, status, reason, log =
690-
run_sandboxed_test(job.install, job.pkg; cache=job.cache,
691-
storage=storage, cpus=[i-1], kwargs...)
706+
runner(install, pkg; cache=cache,
707+
storage=storage, cpus=[i-1], kwargs...)
692708
end
693709
end
694710

695711
duration = (now()-times[i]) / Millisecond(1000)
696-
push!(result, [job.julia, job.pkg.name, job.pkg.uuid, pkg_version,
712+
push!(result, [config.julia, config.compiled,
713+
pkg.name, pkg.uuid, pkg_version,
697714
status, reason, duration, log])
698715
running[i] = nothing
699716
end
@@ -711,7 +728,7 @@ function run(julia_versions::Vector{VersionNumber}, pkgs::Vector;
711728
println()
712729

713730
# clean-up
714-
for (julia, (install,cache)) in julia_environments
731+
for (config, (install,cache)) in instantiated_configs
715732
rm(install; recursive=true)
716733
uid = ccall(:getuid, Cint, ())
717734
gid = ccall(:getgid, Cint, ())
@@ -726,21 +743,24 @@ function run(julia_versions::Vector{VersionNumber}, pkgs::Vector;
726743
end
727744

728745
"""
729-
run(julia_versions::Vector{VersionNumber}=[Base.VERSION],
746+
run(configs::Vector{Configuration}=[Configuration(julia=Base.VERSION)],
730747
pkg_names::Vector{String}=[]]; registry=General, update_registry=true, kwargs...)
731748
732749
Run all tests for all packages in the registry `registry`, or only for the packages as
733-
identified by their name in `pkgnames`, using Julia versions `julia_versions`.
750+
identified by their name in `pkgnames`, using the configurations from `configs`.
734751
The registry is first updated if `update_registry` is set to true.
735752
736753
Refer to `run_sandboxed_test`[@ref] and `run_sandboxed_julia`[@ref] for more possible
737754
keyword arguments.
738755
"""
739-
function run(julia_versions::Vector{VersionNumber}=[Base.VERSION],
756+
function run(configs::Vector{Configuration}=[Configuration(Base.VERSION)],
740757
pkg_names::Vector{String}=String[];
741758
registry::String=DEFAULT_REGISTRY, update_registry::Bool=true, kwargs...)
742759
prepare_registry(registry; update=update_registry)
743760
pkgs = read_pkgs(pkg_names)
744761

745-
run(julia_versions, pkgs; kwargs...)
762+
run(configs, pkgs; kwargs...)
746763
end
764+
765+
run(julia_versions::Vector{VersionNumber}, args...; kwargs...) =
766+
run(Configuration.(julia_versions), args...; kwargs...)

0 commit comments

Comments
 (0)