Skip to content

Commit b18b854

Browse files
committed
tests: add jgf_shorthand graph update test
Problem: there are no tests for reading in jgf_shorthand and using it to update the graph. Add a basic test.
1 parent e56193b commit b18b854

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

t/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ set(ALL_TESTS
7373
t3038-resource-flexible.t
7474
t3039-resource-force-load-format.t
7575
t3040-jgf-shorthand-match-format.t
76+
t3041-jgf-shorthand-load-format.t
7677
t3300-system-dontblock.t
7778
t3301-system-latestart.t
7879
t4000-match-params.t
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/sh
2+
3+
test_description='Test the jgf_shorthand load format'
4+
5+
. $(dirname $0)/sharness.sh
6+
7+
query="../../resource/utilities/resource-query"
8+
9+
echo \
10+
"version: 9999
11+
resources:
12+
- type: node
13+
count: 10
14+
with:
15+
- type: slot
16+
count: 1
17+
label: default
18+
with:
19+
- type: core
20+
count: 8
21+
- type: gpu
22+
count: 2
23+
attributes:
24+
system:
25+
duration: 3600
26+
tasks:
27+
- command: [ \"app\" ]
28+
slot: default
29+
count:
30+
per_slot: 1
31+
" > jobspec.yaml
32+
33+
test_expect_success 'Generate rv1 with .scheduling key' '
34+
flux R encode --hosts=compute[1-10] --cores=0-7 --gpu=0-1 | jq . > R.json &&
35+
cat R.json | flux ion-R encode > R_JGF.json &&
36+
jq -S "del(.execution.starttime, .execution.expiration)" R.json > R.norm.json
37+
'
38+
39+
test_expect_success 'resource_query can be loaded with jgf_shorthand reader' '
40+
cat > match_jobspec_cmd <<-EOF &&
41+
match allocate jobspec.yaml
42+
quit
43+
EOF
44+
jq -S .scheduling R_JGF.json > JGF.json &&
45+
${query} -L JGF.json -f jgf_shorthand -F rv1_nosched -t R1.out -P high < match_jobspec_cmd &&
46+
head -n1 R1.out | jq -S "del(.execution.starttime, .execution.expiration)" > r_match.json &&
47+
test_cmp r_match.json R.norm.json
48+
'
49+
50+
test_expect_success 'generate jgf_shorthand to use to update regular JGF' '
51+
${query} -L JGF.json -f jgf_shorthand -F jgf_shorthand -t jgf1.out -P lonodex < match_jobspec_cmd &&
52+
head -n1 jgf1.out | jq -S . > shorthand.json &&
53+
test_must_fail grep core shorthand.json > /dev/null &&
54+
test_must_fail grep gpu shorthand.json > /dev/null &&
55+
grep node shorthand.json > /dev/null &&
56+
grep compute1 shorthand.json > /dev/null
57+
'
58+
59+
test_expect_success 'update graph to allocate a job using jgf_shorthand' '
60+
cat > update_allocate_cmd <<-EOF &&
61+
update allocate jgf_shorthand shorthand.json 0 0 5
62+
f sched-now=allocated
63+
quit
64+
EOF
65+
jq -S .scheduling R_JGF.json > JGF.json &&
66+
${query} -L JGF.json -f jgf_shorthand -F jgf -t jgf2.out -P high < update_allocate_cmd &&
67+
tail -n4 jgf2.out | head -n1 > allocated.json
68+
'
69+
70+
test_expect_success 'JGF output shows all cores and gpus allocated' '
71+
grep core allocated.json > /dev/null &&
72+
grep gpu allocated.json > /dev/null &&
73+
grep node allocated.json > /dev/null &&
74+
grep compute1 allocated.json > /dev/null &&
75+
jq -e ".graph.nodes[] | select(.metadata.type == \"core\") | .id" allocated.json > cores.json &&
76+
test 80 -eq $(cat cores.json | wc -l) &&
77+
jq -e ".graph.nodes[] | select(.metadata.type == \"gpu\") | .id" allocated.json > gpus.json &&
78+
test 20 -eq $(cat gpus.json | wc -l)
79+
'
80+
81+
test_done

0 commit comments

Comments
 (0)