Skip to content

Commit f6e84a2

Browse files
committed
add tests to script.jl
1 parent 6317ab1 commit f6e84a2

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

test/runtests.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,27 @@ using Distributed, Test, SlurmClusterManager
99
jobid = read(`sbatch --export=ALL --parsable -n 4 -o test.out script.jl`, String)
1010
println("jobid = $jobid")
1111

12+
# get job state from jobid
13+
getjobstate = jobid -> read(`sacct -j $jobid --format=state --noheader`, String)
14+
1215
# wait for job to complete
1316
status = timedwait(60.0, pollint=1.0) do
14-
state = read(`sacct -j $jobid --format=state --noheader`, String)
17+
state = getjobstate(jobid)
1518
state == "" && return false
1619
state = first(split(state)) # don't care about jobsteps
1720
println("jobstate = $state")
1821
return state == "COMPLETED" || state == "FAILED"
1922
end
23+
24+
# check that job finished running within timelimit (either completed or failed)
2025
@test status == :ok
2126

22-
output = readlines("test.out")
23-
println(output)
27+
state = getjobstate(jobid) |> split
28+
# length should be two because creating the workers creates a job step
29+
@test length(state) == 2
30+
31+
# check that everything exited without errors
32+
@test all(state .== "COMPLETED")
33+
34+
# print job output
35+
read("test.out", String) |> print

test/script.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#!/usr/bin/env julia
22

3-
using Distributed, SlurmClusterManager
3+
using Test, Distributed, SlurmClusterManager
44
addprocs(SlurmManager())
5-
@everywhere println("hello from $(myid()):$(gethostname())")
5+
6+
@test nworkers() == parse(Int, ENV["SLURM_NTASKS"])
7+
8+
hosts = map(workers()) do id
9+
remotecall_fetch(() -> gethostname(), id)
10+
end
11+
sort!(hosts)
12+
13+
@test hosts == ["c1", "c1", "c2", "c2"]

0 commit comments

Comments
 (0)