|
2 | 2 |
|
3 | 3 | using Distributed, Test, SlurmClusterManager |
4 | 4 |
|
5 | | -# test that slurm is available |
6 | | -@test !(Sys.which("sinfo") === nothing) |
7 | | - |
8 | | -# submit job |
9 | | -# project should point to top level dir so that SlurmClusterManager is available to script.jl |
10 | | -project_path = abspath(joinpath(@__DIR__, "..")) |
11 | | -println("project_path = $project_path") |
12 | | -jobid = withenv("JULIA_PROJECT"=>project_path) do |
13 | | - strip(read(`sbatch --export=ALL --parsable -n 4 -o test.out script.jl`, String)) |
14 | | -end |
15 | | -println("jobid = $jobid") |
16 | | - |
17 | | -# get job state from jobid |
18 | | -getjobstate = jobid -> begin |
19 | | - cmd = Cmd(`scontrol show jobid=$jobid`, ignorestatus=true) |
20 | | - info = read(cmd, String) |
21 | | - state = match(r"JobState=(\S*)", info) |
22 | | - return state === nothing ? nothing : state.captures[1] |
23 | | -end |
24 | | - |
25 | | -# wait for job to complete |
26 | | -status = timedwait(60.0, pollint=1.0) do |
| 5 | +@testset "SlurmClusterManager.jl" begin |
| 6 | + # test that slurm is available |
| 7 | + @test !(Sys.which("sinfo") === nothing) |
| 8 | + |
| 9 | + # submit job |
| 10 | + # project should point to top level dir so that SlurmClusterManager is available to script.jl |
| 11 | + project_path = abspath(joinpath(@__DIR__, "..")) |
| 12 | + println("project_path = $project_path") |
| 13 | + jobid = withenv("JULIA_PROJECT"=>project_path) do |
| 14 | + strip(read(`sbatch --export=ALL --parsable -n 4 -o test.out script.jl`, String)) |
| 15 | + end |
| 16 | + println("jobid = $jobid") |
| 17 | + |
| 18 | + # get job state from jobid |
| 19 | + getjobstate = jobid -> begin |
| 20 | + cmd = Cmd(`scontrol show jobid=$jobid`, ignorestatus=true) |
| 21 | + info = read(cmd, String) |
| 22 | + state = match(r"JobState=(\S*)", info) |
| 23 | + return state === nothing ? nothing : state.captures[1] |
| 24 | + end |
| 25 | + |
| 26 | + # wait for job to complete |
| 27 | + status = timedwait(60.0, pollint=1.0) do |
| 28 | + state = getjobstate(jobid) |
| 29 | + state == nothing && return false |
| 30 | + println("jobstate = $state") |
| 31 | + return state == "COMPLETED" || state == "FAILED" |
| 32 | + end |
| 33 | + |
27 | 34 | state = getjobstate(jobid) |
28 | | - state == nothing && return false |
29 | | - println("jobstate = $state") |
30 | | - return state == "COMPLETED" || state == "FAILED" |
31 | | -end |
32 | | - |
33 | | -state = getjobstate(jobid) |
34 | | - |
35 | | -# check that job finished running within timelimit (either completed or failed) |
36 | | -@test status == :ok |
37 | | -@test state == "COMPLETED" |
38 | | - |
39 | | -# print job output |
40 | | -output = read("test.out", String) |
41 | | -println("script output:") |
42 | | -println(output) |
| 35 | + |
| 36 | + # check that job finished running within timelimit (either completed or failed) |
| 37 | + @test status == :ok |
| 38 | + @test state == "COMPLETED" |
| 39 | + |
| 40 | + # print job output |
| 41 | + output = read("test.out", String) |
| 42 | + println("script output:") |
| 43 | + println(output) |
| 44 | + |
| 45 | +end # testset "SlurmClusterManager.jl" |
0 commit comments