Skip to content

Commit cdb3a9e

Browse files
committed
Test suite: Add coverage for some "unhappy" paths (error paths)
1 parent df626ee commit cdb3a9e

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

test/error_path_intentionally_fail.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
mktempdir() do tmpdir
2+
fake_bindir = joinpath(tmpdir, "bin")
3+
fake_srun = joinpath(tmpdir, "bin", "srun")
4+
mkpath(fake_bindir)
5+
open(fake_srun, "w") do io
6+
println(io, "#!/usr/bin/env bash")
7+
println(io, "set -euf -o pipefail")
8+
# println(io, "set -x")
9+
println(io, "echo [stdout] fake-srun: INTENTIONALLY ERROR-ING")
10+
println(io, "echo [stderr] fake-srun: INTENTIONALLY ERROR-ING >&2")
11+
println(io, "exit 1")
12+
end
13+
chmod(fake_srun, 0o700) # chmod +x
14+
directory_separator = Sys.iswindows() ? ';' : ':'
15+
new_env = Dict{String, String}()
16+
new_env["SLURM_NTASKS"] = "8"
17+
new_env["SLURM_JOB_ID"] = "1234"
18+
if haskey(ENV, "PATH")
19+
old_path = ENV["PATH"]
20+
new_env["PATH"] = fake_bindir * directory_separator * old_path
21+
else
22+
new_env["PATH"] = fake_bindir
23+
end
24+
25+
@info "with old PATH" Sys.which("srun")
26+
withenv(new_env...) do
27+
@info "with new PATH" Sys.which("srun")
28+
if Base.VERSION >= v"1.2-"
29+
T_expected = TaskFailedException
30+
else
31+
T_expected = Base.IOError
32+
end
33+
mgr = SlurmClusterManager.SlurmManager()
34+
@test_throws T_expected Distributed.addprocs(mgr)
35+
end
36+
end

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ end
1919
@testset "Unit tests" begin
2020
include("unit.jl")
2121
end
22+
23+
@testset "Test some unhappy paths (error paths)" begin
24+
include("error_path_intentionally_fail.jl")
25+
end
2226

2327
# test that slurm is available
2428
@test !(Sys.which("sinfo") === nothing)

0 commit comments

Comments
 (0)