Skip to content

Commit b98a38f

Browse files
authored
test: Retry rm if it failed (#1100)
1 parent 686b959 commit b98a38f

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

test/runtests.jl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ if is_slow_ci
3535
@warn "This is \"slow CI\" (defined as any non-macOS CI running on aarch64). Some tests will be skipped or modified." Sys.ARCH
3636
end
3737

38+
# Sometimes directories seem to fail to clean up on CI (for undiagnosed
39+
# reasons), so retry them.
40+
function rm_with_retry(path; recursive::Bool=false, force::Bool=false,
41+
attempts::Int=5, delay::Real=0.5)
42+
for i in 1:attempts
43+
try
44+
rm(path; recursive=recursive, force=force)
45+
return
46+
catch e
47+
(e isa Base.IOError && i < attempts) || rethrow()
48+
sleep(delay)
49+
end
50+
end
51+
end
52+
3853
@testset "PackageCompiler.jl" begin
3954
@testset "create_sysimage" begin
4055
new_project = mktempdir()
@@ -104,11 +119,11 @@ end
104119
"Undefined" => "undefined",
105120
])
106121
finally
107-
rm(tmp_app_source_dir; recursive=true)
122+
rm_with_retry(tmp_app_source_dir; recursive=true)
108123
# Get rid of some local state
109-
rm(joinpath(new_depot, "packages"); recursive=true, force=true)
110-
rm(joinpath(new_depot, "compiled"); recursive=true, force=true)
111-
rm(joinpath(new_depot, "artifacts"); recursive=true, force=true)
124+
rm_with_retry(joinpath(new_depot, "packages"); recursive=true, force=true)
125+
rm_with_retry(joinpath(new_depot, "compiled"); recursive=true, force=true)
126+
rm_with_retry(joinpath(new_depot, "artifacts"); recursive=true, force=true)
112127
end # try
113128
test_load_path = mktempdir()
114129
test_depot_path = mktempdir()
@@ -201,7 +216,7 @@ end
201216
precompile_execution_file=joinpath(lib_source_dir, "build", "generate_precompile.jl"),
202217
precompile_statements_file=joinpath(lib_source_dir, "build", "additional_precompile.jl"),
203218
lib_name=lib_name, version=v"1.0.0")
204-
rm(tmp_lib_src_dir; recursive=true)
219+
rm_with_retry(tmp_lib_src_dir; recursive=true)
205220
end
206221

207222
# Test creating an empty sysimage

0 commit comments

Comments
 (0)