Skip to content

Commit 30db1a6

Browse files
chu11mergify[bot]
authored andcommitted
testsuite: move common funcs to helper file
Problem: Common helper code in t2260-job-list and t2261-job-list-update will be useful in future tests. Solution: Move them into a new job-list-helper.sh file to remove code redundancy.
1 parent d1cf3fe commit 30db1a6

File tree

4 files changed

+75
-103
lines changed

4 files changed

+75
-103
lines changed

t/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ dist_check_SCRIPTS = \
323323
job-exec/imp-fail.sh \
324324
job-list/list-id.py \
325325
job-list/list-rpc.py \
326+
job-list/job-list-helper.sh \
326327
job-list/jobspec-permissive.jsonschema \
327328
ingest/bad-validate.py
328329

t/job-list/job-list-helper.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/sh
2+
#
3+
4+
# job-list test helper functions
5+
6+
JOB_LIST_WAIT_ITERS=50
7+
8+
# Return the expected jobids list in a given state:
9+
# "all", "pending", "running", "inactive", "active",
10+
# "completed", "canceled", "failed"
11+
#
12+
job_list_state_ids() {
13+
for f in "$@"; do
14+
cat ${f}.ids
15+
done
16+
}
17+
18+
# Return the expected count of jobs in a given state (See above for list)
19+
#
20+
job_list_state_count() {
21+
job_list_state_ids "$@" | wc -l
22+
}
23+
24+
# the job-list module has eventual consistency with the jobs stored in
25+
# the job-manager's queue. To ensure no raciness in tests, we spin
26+
# until all of the pending jobs have reached SCHED state, running jobs
27+
# have reached RUN state, and inactive jobs have reached INACTIVE
28+
# state.
29+
#
30+
# job ids for jobs in these states are expected to be in pending.ids,
31+
# running.ids, and inactive.ids respectively.
32+
33+
job_list_wait_states() {
34+
pending=$(job_list_state_count pending)
35+
running=$(job_list_state_count running)
36+
inactive=$(job_list_state_count inactive)
37+
local i=0
38+
while ( [ "$(flux job list --states=sched | wc -l)" != "$pending" ] \
39+
|| [ "$(flux job list --states=run | wc -l)" != "$running" ] \
40+
|| [ "$(flux job list --states=inactive | wc -l)" != "$inactive" ]) \
41+
&& [ $i -lt ${JOB_LIST_WAIT_ITERS} ]
42+
do
43+
sleep 0.1
44+
i=$((i + 1))
45+
done
46+
if [ "$i" -eq "${JOB_LIST_WAIT_ITERS}" ]
47+
then
48+
return 1
49+
fi
50+
return 0
51+
}

t/t2260-job-list.t

Lines changed: 20 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
test_description='Test flux job list services'
44

5+
. $(dirname $0)/job-list/job-list-helper.sh
6+
57
. $(dirname $0)/sharness.sh
68

79
test_under_flux 4 job
@@ -49,48 +51,6 @@ wait_jobid_state() {
4951
# TODO
5052
# - alternate userid job listing
5153

52-
# Return the expected jobids list in a given state:
53-
# "all", "pending", "running", "inactive", "active",
54-
# "completed", "canceled", "failed"
55-
#
56-
state_ids() {
57-
for f in "$@"; do
58-
cat ${f}.ids
59-
done
60-
}
61-
62-
# Return the expected count of jobs in a given state (See above for list)
63-
#
64-
state_count() {
65-
state_ids "$@" | wc -l
66-
}
67-
68-
# the job-list module has eventual consistency with the jobs stored in
69-
# the job-manager's queue. To ensure no raciness in tests, we spin
70-
# until all of the pending jobs have reached SCHED state, running jobs
71-
# have reached RUN state, and inactive jobs have reached INACTIVE
72-
# state.
73-
74-
wait_states() {
75-
pending=$(state_count pending)
76-
running=$(state_count running)
77-
inactive=$(state_count inactive)
78-
local i=0
79-
while ( [ "$(flux job list --states=sched | wc -l)" != "$pending" ] \
80-
|| [ "$(flux job list --states=run | wc -l)" != "$running" ] \
81-
|| [ "$(flux job list --states=inactive | wc -l)" != "$inactive" ]) \
82-
&& [ $i -lt 50 ]
83-
do
84-
sleep 0.1
85-
i=$((i + 1))
86-
done
87-
if [ "$i" -eq "50" ]
88-
then
89-
return 1
90-
fi
91-
return 0
92-
}
93-
9454
test_expect_success 'submit jobs for job list testing' '
9555
# Create `hostname` and `sleep` jobspec
9656
# N.B. Used w/ `flux job submit` for serial job submission
@@ -159,7 +119,7 @@ test_expect_success 'submit jobs for job list testing' '
159119
#
160120
# Synchronize all expected states
161121
#
162-
wait_states
122+
job_list_wait_states
163123
'
164124

165125
# Note: "running" = "run" | "cleanup", we also test just "run" state
@@ -321,7 +281,7 @@ test_expect_success HAVE_JQ 'flux job list active jobs in correct order' '
321281
'
322282

323283
test_expect_success HAVE_JQ 'flux job list jobs with correct userid' '
324-
for count in `seq 1 $(state_count all)`; do \
284+
for count in `seq 1 $(job_list_state_count all)`; do \
325285
id -u >> list_userid.exp; \
326286
done &&
327287
flux job list -a | jq .userid > list_userid.out &&
@@ -331,21 +291,21 @@ test_expect_success HAVE_JQ 'flux job list jobs with correct userid' '
331291
test_expect_success HAVE_JQ 'flux job list defaults to listing pending & running jobs' '
332292
flux job list | jq .id > list_default.out &&
333293
count=$(wc -l < list_default.out) &&
334-
test $count = $(state_count active) &&
294+
test $count = $(job_list_state_count active) &&
335295
test_cmp list_default.out active.ids
336296
'
337297

338298
test_expect_success 'flux job list --user=userid works' '
339299
uid=$(id -u) &&
340300
flux job list --user=$uid> list_userid.out &&
341301
count=$(wc -l < list_userid.out) &&
342-
test $count = $(state_count active)
302+
test $count = $(job_list_state_count active)
343303
'
344304

345305
test_expect_success 'flux job list --user=all works' '
346306
flux job list --user=all > list_all.out &&
347307
count=$(wc -l < list_all.out) &&
348-
test $count = $(state_count active)
308+
test $count = $(job_list_state_count active)
349309
'
350310

351311
# we hard count numbers here b/c its a --count test
@@ -366,11 +326,11 @@ test_expect_success HAVE_JQ 'flux job list all jobs works' '
366326
test_expect_success HAVE_JQ 'job stats lists jobs in correct state (mix)' '
367327
flux job stats | jq -e ".job_states.depend == 0" &&
368328
flux job stats | jq -e ".job_states.priority == 0" &&
369-
flux job stats | jq -e ".job_states.sched == $(state_count pending)" &&
370-
flux job stats | jq -e ".job_states.run == $(state_count running)" &&
329+
flux job stats | jq -e ".job_states.sched == $(job_list_state_count pending)" &&
330+
flux job stats | jq -e ".job_states.run == $(job_list_state_count running)" &&
371331
flux job stats | jq -e ".job_states.cleanup == 0" &&
372-
flux job stats | jq -e ".job_states.inactive == $(state_count inactive)" &&
373-
flux job stats | jq -e ".job_states.total == $(state_count all)"
332+
flux job stats | jq -e ".job_states.inactive == $(job_list_state_count inactive)" &&
333+
flux job stats | jq -e ".job_states.total == $(job_list_state_count all)"
374334
'
375335

376336
test_expect_success 'cleanup job listing jobs ' '
@@ -382,7 +342,7 @@ test_expect_success 'cleanup job listing jobs ' '
382342

383343
wait_inactive() {
384344
local i=0
385-
while [ "$(flux job list --states=inactive | wc -l)" != "$(state_count all)" ] \
345+
while [ "$(flux job list --states=inactive | wc -l)" != "$(job_list_state_count all)" ] \
386346
&& [ $i -lt 50 ]
387347
do
388348
sleep 0.1
@@ -412,21 +372,21 @@ test_expect_success HAVE_JQ 'job stats lists jobs in correct state (all inactive
412372
flux job stats | jq -e ".job_states.sched == 0" &&
413373
flux job stats | jq -e ".job_states.run == 0" &&
414374
flux job stats | jq -e ".job_states.cleanup == 0" &&
415-
flux job stats | jq -e ".job_states.inactive == $(state_count all)" &&
416-
flux job stats | jq -e ".job_states.total == $(state_count all)"
375+
flux job stats | jq -e ".job_states.inactive == $(job_list_state_count all)" &&
376+
flux job stats | jq -e ".job_states.total == $(job_list_state_count all)"
417377
'
418378

419379
# job list-inactive
420380

421381
test_expect_success HAVE_JQ 'flux job list-inactive lists all inactive jobs' '
422382
flux job list-inactive > list-inactive.out &&
423383
count=`cat list-inactive.out | wc -l` &&
424-
test $count -eq $(state_count all)
384+
test $count -eq $(job_list_state_count all)
425385
'
426386

427387
test_expect_success HAVE_JQ 'flux job list-inactive w/ since 0 lists all inactive jobs' '
428388
count=`flux job list-inactive --since=0 | wc -l` &&
429-
test $count -eq $(state_count all)
389+
test $count -eq $(job_list_state_count all)
430390
'
431391

432392
# we hard count numbers here b/c its a --count test
@@ -486,16 +446,16 @@ test_expect_success HAVE_JQ 'flux job list-ids works with a single ID' '
486446
'
487447

488448
test_expect_success HAVE_JQ 'flux job list-ids multiple IDs works' '
489-
ids=$(state_ids pending) &&
449+
ids=$(job_list_state_ids pending) &&
490450
flux job list-ids $ids | jq .id > list_idsP.out &&
491451
test_cmp list_idsP.out pending.ids &&
492-
ids=$(state_ids running) &&
452+
ids=$(job_list_state_ids running) &&
493453
flux job list-ids $ids | jq .id > list_idsR.out &&
494454
test_cmp list_idsR.out running.ids &&
495-
ids=$(state_ids inactive) &&
455+
ids=$(job_list_state_ids inactive) &&
496456
flux job list-ids $ids | jq .id > list_idsI.out &&
497457
test_cmp list_idsI.out inactive.ids &&
498-
ids=$(state_ids all) &&
458+
ids=$(job_list_state_ids all) &&
499459
flux job list-ids $ids | jq .id > list_idsPRI.out &&
500460
cat pending.ids running.ids inactive.ids > list_idsPRI.exp &&
501461
test_cmp list_idsPRI.exp list_idsPRI.out

t/t2261-job-list-update.t

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
test_description='Test flux job list services w/ changing job data'
44

5+
. $(dirname $0)/job-list/job-list-helper.sh
6+
57
. $(dirname $0)/sharness.sh
68

79
test_under_flux 4 job
@@ -29,48 +31,6 @@ fj_wait_event() {
2931
# TODO
3032
# - alternate userid job listing
3133

32-
# Return the expected jobids list in a given state:
33-
# "all", "pending", "running", "inactive", "active",
34-
# "completed", "canceled", "failed"
35-
#
36-
state_ids() {
37-
for f in "$@"; do
38-
cat ${f}.ids
39-
done
40-
}
41-
42-
# Return the expected count of jobs in a given state (See above for list)
43-
#
44-
state_count() {
45-
state_ids "$@" | wc -l
46-
}
47-
48-
# the job-list module has eventual consistency with the jobs stored in
49-
# the job-manager's queue. To ensure no raciness in tests, we spin
50-
# until all of the pending jobs have reached SCHED state, running jobs
51-
# have reached RUN state, and inactive jobs have reached INACTIVE
52-
# state.
53-
54-
wait_states() {
55-
pending=$(state_count pending)
56-
running=$(state_count running)
57-
inactive=$(state_count inactive)
58-
local i=0
59-
while ( [ "$(flux job list --states=sched | wc -l)" != "$pending" ] \
60-
|| [ "$(flux job list --states=run | wc -l)" != "$running" ] \
61-
|| [ "$(flux job list --states=inactive | wc -l)" != "$inactive" ]) \
62-
&& [ $i -lt 50 ]
63-
do
64-
sleep 0.1
65-
i=$((i + 1))
66-
done
67-
if [ "$i" -eq "50" ]
68-
then
69-
return 1
70-
fi
71-
return 0
72-
}
73-
7434
test_expect_success 'submit jobs for job list testing' '
7535
# Create `hostname` and `sleep` jobspec
7636
# N.B. Used w/ `flux job submit` for serial job submission
@@ -123,7 +83,7 @@ test_expect_success 'submit jobs for job list testing' '
12383
#
12484
# Synchronize all expected states
12585
#
126-
wait_states
86+
job_list_wait_states
12787
'
12888

12989
# Note: "running" = "run" | "cleanup", we also test just "run" state

0 commit comments

Comments
 (0)