Skip to content

Commit

Permalink
Ensure precompilation when testing runs without threads on Julia 1.11
Browse files Browse the repository at this point in the history
Fixes JuliaLang/julia#56458

Precompilation with threads is not supported: JuliaLang/julia#53572 (comment)

Ensures that tests run with threads, both when calling `julia --project --threads=auto --eval 'using Pkg; Pkg.test()'`, and when calling `julia --project --eval 'using Pkg; Pkg.test(; julia_args = ["--threads=auto"])'`.
  • Loading branch information
stemann committed Jan 25, 2025
1 parent 2eb8ae5 commit 6c64500
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2060,19 +2060,21 @@ function test(ctx::Context, pkgs::Vector{PackageSpec};
test_fn !== nothing && test_fn()
sandbox_ctx = Context(;io=ctx.io)
status(sandbox_ctx.env, sandbox_ctx.registries; mode=PKGMODE_COMBINED, io=sandbox_ctx.io, ignore_indent = false, show_usagetips = false)
flags = gen_subprocess_flags(source_path; coverage,julia_args)
precompile_julia_args = Cmd(filter(!startswith("--threads"), julia_args.exec)) # precompilation with threads is not supported
precompile_flags = gen_subprocess_flags(source_path; coverage, julia_args = precompile_julia_args)

if should_autoprecompile()
cacheflags = Base.CacheFlags(parse(UInt8, read(`$(Base.julia_cmd()) $(flags) --eval 'show(ccall(:jl_cache_flags, UInt8, ()))'`, String)))
cacheflags = Base.CacheFlags(parse(UInt8, read(`$(Base.julia_cmd()) $(precompile_flags) --eval 'show(ccall(:jl_cache_flags, UInt8, ()))'`, String)))
Pkg.activate(sandbox_ctx.env.project_file; #=io=devnull=#) do
Pkg.precompile(sandbox_ctx; io=sandbox_ctx.io, configs = flags => cacheflags)
Pkg.precompile(sandbox_ctx; io=sandbox_ctx.io, configs = precompile_flags => cacheflags)
end
end

printpkgstyle(ctx.io, :Testing, "Running tests...")
flush(ctx.io)
code = gen_test_code(source_path; test_args)
cmd = `$(Base.julia_cmd()) $(flags) --threads=$(get_threads_spec()) --eval $code`
flags = gen_subprocess_flags(source_path; coverage, julia_args = julia_args)
cmd = `$(Base.julia_cmd()) --threads=$(get_threads_spec()) $(flags) --eval $code`
p, interrupted = subprocess_handler(cmd, ctx, sandbox_ctx, "Tests interrupted. Exiting the test process")
if success(p)
printpkgstyle(ctx.io, :Testing, pkg.name * " tests passed ")
Expand Down

0 comments on commit 6c64500

Please sign in to comment.