Skip to content

Commit cb288d3

Browse files
add atomic usage file test
1 parent e1ee0a7 commit cb288d3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/pkg.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,29 @@ temp_pkg_dir() do project_path
363363
@test any(x -> startswith(x, manifest), keys(usage))
364364
end
365365

366+
@testset "atomic write_env_usage with $(Sys.CPU_THREADS) processes for 10 seconds" begin
367+
tasks = Task[]
368+
iobs = IOBuffer[]
369+
Sys.CPU_THREADS == 1 && error("Cannot test for atomic usage log file interaction effectively with only Sys.CPU_THREADS=1")
370+
for i in 1:Sys.CPU_THREADS
371+
iob = IOBuffer()
372+
t = @async run(pipeline(`$(Base.julia_cmd()) --project="$(pkgdir(Pkg))"
373+
-e "import Pkg; t = Timer(10); while isopen(t) Pkg.activate(temp = true); Pkg.Types.EnvCache(); end"`,
374+
stderr = iob, stdout = devnull))
375+
push!(tasks, t)
376+
push!(iobs, iob)
377+
end
378+
for i in eachindex(tasks)
379+
try
380+
fetch(tasks[i]) # If any of these failed it will throw when fetched
381+
catch
382+
print(String(take!(iobs[i])))
383+
break
384+
end
385+
end
386+
@test any(istaskfailed, tasks) == false
387+
end
388+
366389
@testset "adding nonexisting packages" begin
367390
nonexisting_pkg = randstring(14)
368391
@test_throws PkgError Pkg.add(nonexisting_pkg)

0 commit comments

Comments
 (0)