Skip to content

Commit bf67f63

Browse files
authored
test: isolate more tests that call subprocesses (#4504)
* test: isolate more tests that call subprocesses The base `make test-Pkg` invocation sets JULIA_DEPOT_PATH to the builtin DEPOT_PATH. However, Pkg tests assume that this DEPOT_PATH do not have any registries. There were various places where we were accidentally using this DEPOT_PATH and installing a registry there. Work around this by unsetting it, isolating some subprocesses and adding a check on CI that fails if any pre-set JULIA_DEPOT_PATH gets modified. Ref JuliaLang/julia#60058 * See if Linux would work at least * code format * Try windows env setup * One more format complaint * Run with JULIA_DEBUG to debug loading failures * Use runner rather than matrix in conditional * More debug logging * Embarassing typo * rm CI check again
1 parent 7302e19 commit bf67f63

File tree

7 files changed

+198
-174
lines changed

7 files changed

+198
-174
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ jobs:
5757
julia-version: 'nightly'
5858
pkg-server: "pkg.julialang.org"
5959
steps:
60-
- name: Set git to use LF and fix TEMP on windows
61-
if: matrix.os == 'windows-latest'
60+
- name: Set git to use LF, fix TEMP, set JULIA_DEPOT_PATH (windows)
61+
if: runner.os == 'Windows'
6262
run: |
6363
git config --global core.autocrlf false
6464
git config --global core.eol lf

test/api.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import .FakeTerminals.FakeTerminal
5050

5151
@testset "Pkg.precompile" begin
5252
# sequential precompile, depth-first
53-
isolate() do;
53+
isolate(loaded_depot = true) do;
5454
cd_tempdir() do tmp
5555
Pkg.activate(".")
5656
cd(mkdir("packages")) do
@@ -261,7 +261,8 @@ import .FakeTerminals.FakeTerminal
261261
Pkg.activate(\"$(escape_string(proj))\")
262262
Pkg.precompile()
263263
"`,
264-
"JULIA_PKG_PRECOMPILE_AUTO" => "0"
264+
"JULIA_PKG_PRECOMPILE_AUTO" => "0",
265+
"JULIA_DEPOT_PATH" => join(Base.DEPOT_PATH, Sys.iswindows() ? ";" : ":"),
265266
)
266267
iob1 = IOBuffer()
267268
iob2 = IOBuffer()

test/new.jl

Lines changed: 127 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ Pkg._auto_gc_enabled[] = false
143143
end
144144
end
145145
end
146+
copy_this_pkg_cache(LOADED_DEPOT)
146147
end
147148

148149
function kill_with_info(p)
@@ -171,62 +172,62 @@ end
171172
@testset "Concurrent setup/installation/precompilation across processes" begin
172173
@testset for test in 1:1 # increase for stress testing
173174
mktempdir() do tmp
174-
copy_this_pkg_cache(tmp)
175175
pathsep = Sys.iswindows() ? ";" : ":"
176176
Pkg_dir = dirname(@__DIR__)
177-
withenv("JULIA_DEPOT_PATH" => string(tmp, pathsep)) do
178-
script = """
179-
using Dates
180-
t = Timer(t->println(stderr, Dates.now()), 4*60; interval = 10)
181-
import Pkg
182-
samefile(pkgdir(Pkg), $(repr(Pkg_dir))) || error("Using wrong Pkg")
183-
Pkg.activate(temp=true)
184-
Pkg.add(name="FFMPEG", version="0.4") # a package with a lot of deps but fast to load
185-
using FFMPEG
186-
@showtime FFMPEG.exe("-version")
187-
@showtime FFMPEG.exe("-f", "lavfi", "-i", "testsrc=duration=1:size=128x128:rate=10", "-f", "null", "-") # more complete quick test (~10ms)
188-
close(t)
189-
"""
190-
cmd = `$(Base.julia_cmd()) --project=$(dirname(@__DIR__)) --startup-file=no --color=no -e $script`
191-
did_install_package = Threads.Atomic{Int}(0)
192-
did_install_artifact = Threads.Atomic{Int}(0)
193-
any_failed = Threads.Atomic{Bool}(false)
194-
outputs = fill("", 3)
195-
t = @elapsed @sync begin
196-
# All but 1 process should be waiting, so should be ok to run many
197-
for i in 1:3
198-
Threads.@spawn begin
199-
iob = IOBuffer()
200-
start = time()
201-
p = run(pipeline(cmd, stdout = iob, stderr = iob), wait = false)
202-
if timedwait(() -> process_exited(p), 5 * 60; pollint = 1.0) === :timed_out
203-
kill_with_info(p)
204-
end
205-
if !success(p)
206-
Threads.atomic_cas!(any_failed, false, true)
207-
end
208-
str = String(take!(iob))
209-
if occursin(r"Installed FFMPEG ─", str)
210-
Threads.atomic_add!(did_install_package, 1)
211-
end
212-
if occursin(r"Installed artifact FFMPEG ", str)
213-
Threads.atomic_add!(did_install_artifact, 1)
214-
end
215-
outputs[i] = string("=== test $test, process $i. Took $(time() - start) seconds.\n", str)
177+
script = """
178+
using Dates
179+
t = Timer(t->println(stderr, Dates.now()), 4*60; interval = 10)
180+
import Pkg
181+
samefile(pkgdir(Pkg), $(repr(Pkg_dir))) || error("Using wrong Pkg")
182+
Pkg.activate(temp=true)
183+
Pkg.add(name="FFMPEG", version="0.4") # a package with a lot of deps but fast to load
184+
using FFMPEG
185+
@showtime FFMPEG.exe("-version")
186+
@showtime FFMPEG.exe("-f", "lavfi", "-i", "testsrc=duration=1:size=128x128:rate=10", "-f", "null", "-") # more complete quick test (~10ms)
187+
close(t)
188+
"""
189+
cmd = addenv(
190+
`$(Base.julia_cmd()) --project=$(dirname(@__DIR__)) --startup-file=no --color=no -e $script`,
191+
"JULIA_DEPOT_PATH" => join([tmp, LOADED_DEPOT, ""], pathsep)
192+
)
193+
did_install_package = Threads.Atomic{Int}(0)
194+
did_install_artifact = Threads.Atomic{Int}(0)
195+
any_failed = Threads.Atomic{Bool}(false)
196+
outputs = fill("", 3)
197+
t = @elapsed @sync begin
198+
# All but 1 process should be waiting, so should be ok to run many
199+
for i in 1:3
200+
Threads.@spawn begin
201+
iob = IOBuffer()
202+
start = time()
203+
p = run(pipeline(cmd, stdout = iob, stderr = iob), wait = false)
204+
if timedwait(() -> process_exited(p), 5 * 60; pollint = 1.0) === :timed_out
205+
kill_with_info(p)
206+
end
207+
if !success(p)
208+
Threads.atomic_cas!(any_failed, false, true)
209+
end
210+
str = String(take!(iob))
211+
if occursin(r"Installed FFMPEG ─", str)
212+
Threads.atomic_add!(did_install_package, 1)
216213
end
214+
if occursin(r"Installed artifact FFMPEG ", str)
215+
Threads.atomic_add!(did_install_artifact, 1)
216+
end
217+
outputs[i] = string("=== test $test, process $i. Took $(time() - start) seconds.\n", str)
217218
end
218219
end
219-
if any_failed[] || did_install_package[] != 1 || did_install_artifact[] != 1
220-
println("=== Concurrent Pkg.add test $test failed after $t seconds")
221-
for i in 1:3
222-
printstyled(stdout, outputs[i]; color = (:blue, :green, :yellow)[i])
223-
end
220+
end
221+
if any_failed[] || did_install_package[] != 1 || did_install_artifact[] != 1
222+
println("=== Concurrent Pkg.add test $test failed after $t seconds")
223+
for i in 1:3
224+
printstyled(stdout, outputs[i]; color = (:blue, :green, :yellow)[i])
224225
end
225-
# only 1 should have actually installed FFMPEG
226-
@test !any_failed[]
227-
@test did_install_package[] == 1
228-
@test did_install_artifact[] == 1
229226
end
227+
# only 1 should have actually installed FFMPEG
228+
@test !any_failed[]
229+
@test did_install_package[] == 1
230+
@test did_install_artifact[] == 1
230231
end
231232
end
232233
end
@@ -2476,69 +2477,76 @@ end
24762477
end
24772478

24782479
@testset "threads" begin
2479-
mktempdir() do dir
2480-
path = copy_test_package(dir, "TestThreads")
2481-
cd(path) do
2482-
# Do this all in a subprocess to protect against the parent having non-default threadpool sizes.
2483-
script = """
2484-
using Pkg, Test
2485-
@testset "JULIA_NUM_THREADS=1" begin
2486-
withenv(
2487-
"EXPECTED_NUM_THREADS_DEFAULT" => "1",
2488-
"EXPECTED_NUM_THREADS_INTERACTIVE" => "0", # https://github.com/JuliaLang/julia/pull/57454
2489-
"JULIA_NUM_THREADS" => "1",
2490-
) do
2491-
Pkg.test("TestThreads")
2480+
isolate(loaded_depot = true) do;
2481+
mktempdir() do dir
2482+
path = copy_test_package(dir, "TestThreads")
2483+
cd(path) do
2484+
# Do this all in a subprocess to protect against the parent having non-default threadpool sizes.
2485+
script = """
2486+
using Pkg, Test
2487+
@testset "JULIA_NUM_THREADS=1" begin
2488+
withenv(
2489+
"EXPECTED_NUM_THREADS_DEFAULT" => "1",
2490+
"EXPECTED_NUM_THREADS_INTERACTIVE" => "0", # https://github.com/JuliaLang/julia/pull/57454
2491+
"JULIA_NUM_THREADS" => "1",
2492+
) do
2493+
Pkg.test("TestThreads")
2494+
end
24922495
end
2493-
end
2494-
@testset "JULIA_NUM_THREADS=2" begin
2495-
withenv(
2496-
"EXPECTED_NUM_THREADS_DEFAULT" => "2",
2497-
"EXPECTED_NUM_THREADS_INTERACTIVE" => "1",
2498-
"JULIA_NUM_THREADS" => "2",
2499-
) do
2500-
Pkg.test("TestThreads")
2496+
@testset "JULIA_NUM_THREADS=2" begin
2497+
withenv(
2498+
"EXPECTED_NUM_THREADS_DEFAULT" => "2",
2499+
"EXPECTED_NUM_THREADS_INTERACTIVE" => "1",
2500+
"JULIA_NUM_THREADS" => "2",
2501+
) do
2502+
Pkg.test("TestThreads")
2503+
end
25012504
end
2502-
end
2503-
@testset "JULIA_NUM_THREADS=2,0" begin
2504-
withenv(
2505-
"EXPECTED_NUM_THREADS_DEFAULT" => "2",
2506-
"EXPECTED_NUM_THREADS_INTERACTIVE" => "0",
2507-
"JULIA_NUM_THREADS" => "2,0",
2508-
) do
2509-
Pkg.test("TestThreads")
2505+
@testset "JULIA_NUM_THREADS=2,0" begin
2506+
withenv(
2507+
"EXPECTED_NUM_THREADS_DEFAULT" => "2",
2508+
"EXPECTED_NUM_THREADS_INTERACTIVE" => "0",
2509+
"JULIA_NUM_THREADS" => "2,0",
2510+
) do
2511+
Pkg.test("TestThreads")
2512+
end
25102513
end
2511-
end
25122514
2513-
@testset "--threads=1" begin
2514-
withenv(
2515-
"EXPECTED_NUM_THREADS_DEFAULT" => "1",
2516-
"EXPECTED_NUM_THREADS_INTERACTIVE" => "0", # https://github.com/JuliaLang/julia/pull/57454
2517-
"JULIA_NUM_THREADS" => nothing,
2518-
) do
2519-
Pkg.test("TestThreads"; julia_args=`--threads=1`)
2515+
@testset "--threads=1" begin
2516+
withenv(
2517+
"EXPECTED_NUM_THREADS_DEFAULT" => "1",
2518+
"EXPECTED_NUM_THREADS_INTERACTIVE" => "0", # https://github.com/JuliaLang/julia/pull/57454
2519+
"JULIA_NUM_THREADS" => nothing,
2520+
) do
2521+
Pkg.test("TestThreads"; julia_args=`--threads=1`)
2522+
end
25202523
end
2521-
end
2522-
@testset "--threads=2" begin
2523-
withenv(
2524-
"EXPECTED_NUM_THREADS_DEFAULT" => "2",
2525-
"EXPECTED_NUM_THREADS_INTERACTIVE" => "1",
2526-
"JULIA_NUM_THREADS" => nothing,
2527-
) do
2528-
Pkg.test("TestThreads"; julia_args=`--threads=2`)
2524+
@testset "--threads=2" begin
2525+
withenv(
2526+
"EXPECTED_NUM_THREADS_DEFAULT" => "2",
2527+
"EXPECTED_NUM_THREADS_INTERACTIVE" => "1",
2528+
"JULIA_NUM_THREADS" => nothing,
2529+
) do
2530+
Pkg.test("TestThreads"; julia_args=`--threads=2`)
2531+
end
25292532
end
2530-
end
2531-
@testset "--threads=2,0" begin
2532-
withenv(
2533-
"EXPECTED_NUM_THREADS_DEFAULT" => "2",
2534-
"EXPECTED_NUM_THREADS_INTERACTIVE" => "0",
2535-
"JULIA_NUM_THREADS" => nothing,
2536-
) do
2537-
Pkg.test("TestThreads"; julia_args=`--threads=2,0`)
2533+
@testset "--threads=2,0" begin
2534+
withenv(
2535+
"EXPECTED_NUM_THREADS_DEFAULT" => "2",
2536+
"EXPECTED_NUM_THREADS_INTERACTIVE" => "0",
2537+
"JULIA_NUM_THREADS" => nothing,
2538+
) do
2539+
Pkg.test("TestThreads"; julia_args=`--threads=2,0`)
2540+
end
25382541
end
2539-
end
2540-
"""
2541-
@test Utils.show_output_if_command_errors(`$(Base.julia_cmd()) --project=$(path) --startup-file=no -e "$script"`)
2542+
"""
2543+
@test Utils.show_output_if_command_errors(
2544+
addenv(
2545+
`$(Base.julia_cmd()) --project=$(path) --startup-file=no -e "$script"`,
2546+
"JULIA_DEPOT_PATH" => join(Base.DEPOT_PATH, Sys.iswindows() ? ";" : ":")
2547+
)
2548+
)
2549+
end
25422550
end
25432551
end
25442552
end
@@ -3846,18 +3854,20 @@ end
38463854
end
38473855

38483856
@testset "status showing incompatible loaded deps" begin
3849-
cmd = addenv(`$(Base.julia_cmd()) --color=no --startup-file=no -e "
3850-
using Pkg
3851-
Pkg.activate(temp=true)
3852-
Pkg.add(Pkg.PackageSpec(name=\"Example\", version=v\"0.5.4\"))
3853-
using Example
3854-
Pkg.activate(temp=true)
3855-
Pkg.add(Pkg.PackageSpec(name=\"Example\", version=v\"0.5.5\"))
3856-
"`)
3857-
iob = IOBuffer()
3858-
run(pipeline(cmd, stderr = iob, stdout = iob))
3859-
out = String(take!(iob))
3860-
@test occursin("[loaded: v0.5.4]", out)
3857+
isolate(loaded_depot = true) do
3858+
cmd = addenv(`$(Base.julia_cmd()) --color=no --startup-file=no -e "
3859+
using Pkg
3860+
Pkg.activate(temp=true)
3861+
Pkg.add(Pkg.PackageSpec(name=\"Example\", version=v\"0.5.4\"))
3862+
using Example
3863+
Pkg.activate(temp=true)
3864+
Pkg.add(Pkg.PackageSpec(name=\"Example\", version=v\"0.5.5\"))
3865+
"`, "JULIA_DEPOT_PATH" => join(Base.DEPOT_PATH, Sys.iswindows() ? ";" : ":"))
3866+
iob = IOBuffer()
3867+
run(pipeline(cmd, stderr = iob, stdout = iob))
3868+
out = String(take!(iob))
3869+
@test occursin("[loaded: v0.5.4]", out)
3870+
end
38613871
end
38623872

38633873
@test allunique(unique([Pkg.PackageSpec(path = "foo"), Pkg.PackageSpec(path = "foo")]))

0 commit comments

Comments
 (0)