Skip to content

Commit 9daacaa

Browse files
committed
testsuite: add t2814-hostlist-cmd.t
Problem: There are no tests in the testsuite for the flux-hostlist(1) command. Add a set of tests for this command in t2814-hostlist-cmd.t.
1 parent f9a669d commit 9daacaa

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed

t/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ TESTSCRIPTS = \
228228
t2811-flux-pgrep.t \
229229
t2812-flux-job-last.t \
230230
t2813-flux-watch.t \
231+
t2814-hostlist-cmd.t \
231232
t2900-job-timelimits.t \
232233
t3000-mpi-basic.t \
233234
t3001-mpi-personalities.t \

t/t2814-hostlist-cmd.t

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/bin/sh
2+
3+
test_description='Test flux hostlist command'
4+
5+
. $(dirname $0)/sharness.sh
6+
7+
test_under_flux 2
8+
9+
test_expect_success 'flux-hostlist --help works' '
10+
flux hostlist --help >help.out &&
11+
test_debug "cat help.out" &&
12+
grep "SOURCES may include" help.out
13+
'
14+
test_expect_success 'flux-hostlist returns hostlist attr in initial program' '
15+
flux hostlist >hl-instance.out &&
16+
flux getattr hostlist >hl-instance.expected &&
17+
test_cmp hl-instance.expected hl-instance.out
18+
'
19+
test_expect_success 'flux-hostlist returns job hostlist in job' '
20+
flux run flux hostlist >hl-job.out &&
21+
flux jobs -no {nodelist} $(flux job last) > hl-job.expected &&
22+
test_cmp hl-job.expected hl-job.out
23+
'
24+
test_expect_success 'flux-hostlist works with a jobid' '
25+
flux hostlist $(flux job last) >hl-jobid.out &&
26+
test_cmp hl-job.expected hl-jobid.out
27+
'
28+
test_expect_success 'flux-hostlist fails with invalid jobid' '
29+
test_must_fail flux hostlist foo1
30+
'
31+
test_expect_success 'flux-hostlist --fallback treats invalid jobid as host' '
32+
flux hostlist --fallback foo1 >fallback.out &&
33+
test "$(cat fallback.out)" = "foo1"
34+
'
35+
test_expect_success 'flux-hostlist -c works' '
36+
flux hostlist --count &&
37+
test $(flux hostlist --count) -eq 2 &&
38+
test $(flux hostlist -c "foo[1-10]") -eq 10
39+
'
40+
test_expect_success 'flux-hostlist works with "avail"' '
41+
flux resource drain 0 &&
42+
test $(flux hostlist --count avail) -eq 1 &&
43+
flux resource undrain 0
44+
'
45+
test_expect_success 'flux-hostlist works with stdin' '
46+
printf "foo1 foo2 foo3" | flux hostlist - >hl-stdin1.out &&
47+
printf "foo1\nfoo2\nfoo3" | flux hostlist - >hl-stdin2.out &&
48+
test_debug "grep . hl-stdin*.out" &&
49+
printf "foo[1-3]\n" >hl-stdin.expected &&
50+
test_cmp hl-stdin.expected hl-stdin1.out &&
51+
test_cmp hl-stdin.expected hl-stdin2.out
52+
'
53+
test_expect_success 'flux-hostlist works with hostlist args' '
54+
flux hostlist "foo[1-3]" > hl-args1.out &&
55+
flux hostlist --fallback foo1 foo2 foo3 > hl-args2.out &&
56+
printf "foo[1-3]\n" >hl-args.expected &&
57+
test_cmp hl-args.expected hl-args1.out &&
58+
test_cmp hl-args.expected hl-args2.out
59+
'
60+
test_expect_success 'flux-hostlist rejects invalid hostlist' '
61+
test_must_fail flux hostlist "foo[1-"
62+
'
63+
test_expect_success 'flux-hostlist returns empty hostlist for pending job' '
64+
id=$(flux submit --urgency=hold hostname) &&
65+
flux hostlist $id >hl-pending.out &&
66+
test_must_be_empty hl-pending.out
67+
'
68+
# Note job "$id" should still be held when this next test is run:
69+
test_expect_success 'flux-hostlist --quiet works' '
70+
flux hostlist --quiet foo[1-10] > quiet.out &&
71+
test_must_be_empty quiet.out &&
72+
test_must_fail flux hostlist -q $id
73+
'
74+
test_expect_success 'flux-hostlist -e, --expand works' '
75+
test_debug "flux hostlist -e foo[1-3]" &&
76+
test "$(flux hostlist -e foo[1-3])" = "foo1 foo2 foo3" &&
77+
flux hostlist --expand --delimiter="\n" "foo[1-3]" >expand.out &&
78+
cat <<-EOF >expand.expected &&
79+
foo1
80+
foo2
81+
foo3
82+
EOF
83+
test_cmp expand.expected expand.out
84+
'
85+
test_expect_success 'flux-hostlist -n, --nth works' '
86+
test "$(flux hostlist --nth=1 foo[1-10])" = foo2 &&
87+
test "$(flux hostlist --nth=-1 foo[1-10])" = foo10
88+
'
89+
test_expect_success 'flux-hostlist -n errors with invalid index' '
90+
test_must_fail flux hostlist -n 10 foo[1-10]
91+
'
92+
test_expect_success 'flux-hostlist -L, --limit works' '
93+
test "$(flux hostlist -L 2 foo[1-10])" = "foo[1-2]" &&
94+
test "$(flux hostlist -L -2 foo[1-10])" = "foo[9-10]"
95+
'
96+
test_expect_success 'flux-hostlist preserves hostlist order by default' '
97+
test "$(flux hostlist host1 host0 host5 host4)" = "host[1,0,5,4]"
98+
'
99+
test_expect_success 'flux-hostlist preserves repeated hosts by default' '
100+
test "$(flux hostlist host1 host1 host1)" = "host[1,1,1]"
101+
'
102+
test_expect_success 'flux-hostlist -S, --sort works' '
103+
test "$(flux hostlist -S host3 host2 host1 host0)" = "host[0-3]"
104+
'
105+
test_expect_success 'flux-hostlist -S preserves duplicate hosts' '
106+
test "$(flux hostlist -S host2 host1 host3 host1)" = "host[1,1-3]"
107+
'
108+
test_expect_success 'flux-hostlist -u returns union of all hosts' '
109+
test "$(flux hostlist -u host2 host1 host3 host1)" = "host[1-3]" &&
110+
test "$(flux hostlist -u host[1-3] host2)" = "host[1-3]" &&
111+
test "$(flux hostlist -u host[1-3] bar baz)" = "bar,baz,host[1-3]"
112+
'
113+
test_expect_success 'flux-hostlist -i, --intersect works' '
114+
test "$(flux hostlist -i host[1-3] host[2-5])" = "host[2-3]" &&
115+
test "$(flux hostlist -i host[1-3] host[2-5] host[3-10])" = "host3"
116+
'
117+
# Note symmetric difference of 3 sets is all elements that are in just one
118+
# set or all 3 sets due to associative property.
119+
test_expect_success 'flux-hostlist -X, --xor works' '
120+
flux hostlist -X host[1-3] host[2-5] &&
121+
test "$(flux hostlist -X host[1-3] host[2-5])" = "host[1,4-5]" &&
122+
flux hostlist -X host[1-3] host[2-5] host[3-10] &&
123+
test "$(flux hostlist -X host[1-3] host[2-5] host[3-10])" = "host[1,3,6-10]" &&
124+
flux hostlist -X host[3-10] host[1-3] host[2-5] &&
125+
test "$(flux hostlist -X host[3-10] host[1-3] host[2-5])" = "host[1,3,6-10]"
126+
'
127+
test_expect_success 'flux-hostlist -m, --minus works' '
128+
flux hostlist -m host[1-10] host[2-3] &&
129+
test "$(flux hostlist -m host[1-10] host[2-3])" = "host[1,4-10]" &&
130+
flux hostlist -m host[1-10] host[2-3] host[5-10] &&
131+
test "$(flux hostlist -m host[1-10] host[2-3] host[5-10])" = \
132+
"host[1,4]" &&
133+
test "$(flux hostlist -m host[1-10] host[1-20])" = "" &&
134+
test_expect_code 1 flux hostlist -qm host[1-10] host[1-20]
135+
'
136+
test_expect_success 'flux-hostlist -m, --minus removes only first occurrence' '
137+
flux hostlist -m host[1,1,1] host1 &&
138+
test "$(flux hostlist -m host[1,1,1] host1)" = "host[1,1]"
139+
'
140+
test_expect_success 'flux-hostlist: -u can be used with -m' '
141+
flux hostlist -m host[1,1,1] host1 &&
142+
test "$(flux hostlist -um host[1,1,1] host1)" = "host1"
143+
'
144+
test_expect_success 'flux-hostlist -q, --quiet works' '
145+
flux hostlist --quiet host[1-10] >quiet.out &&
146+
test_must_be_empty quiet.out &&
147+
test_must_fail flux hostlist --quiet --intersect host1 host2
148+
'
149+
test_done

0 commit comments

Comments
 (0)