Skip to content

Commit 75a64be

Browse files
committed
testsuite: update job-list consistency checks
Problem: The job-list module has eventual consistency for the jobs that are submitted to the job-manager queue. A number of helper functions have been written to check for this consistency before running tests. These functions are no longer necessary due to the new `flux job list-ids --wait-state` option. Use the flux job list-ids --wait-state option when appropriate. Remove no longer necessary code.
1 parent b658aa9 commit 75a64be

File tree

5 files changed

+25
-94
lines changed

5 files changed

+25
-94
lines changed

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

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#!/bin/sh
22
#
33

4-
# job-list test helper functions
5-
6-
JOB_LIST_WAIT_ITERS=50
7-
84
# Return the expected jobids list in a given state:
95
# "all", "pending", "running", "inactive", "active",
106
# "completed", "canceled", "failed", "timeout"
@@ -20,32 +16,3 @@ job_list_state_ids() {
2016
job_list_state_count() {
2117
job_list_state_ids "$@" | wc -l
2218
}
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: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,10 @@ fj_wait_event() {
1818
flux job wait-event --timeout=20 "$@"
1919
}
2020

21+
# To avoid raciness in tests, need to ensure that job state we care about
22+
# testing against has been reached in the job-list module.
2123
wait_jobid_state() {
22-
local jobid=$(flux job id $1)
23-
local state=$2
24-
local i=0
25-
while ! flux job list --states=${state} | grep $jobid > /dev/null \
26-
&& [ $i -lt 50 ]
27-
do
28-
sleep 0.1
29-
i=$((i + 1))
30-
done
31-
if [ "$i" -eq "50" ]
32-
then
33-
return 1
34-
fi
35-
return 0
24+
flux job list-ids --wait-state=$2 $1 > /dev/null
3625
}
3726

3827
# submit a whole bunch of jobs for job list testing
@@ -147,9 +136,13 @@ test_expect_success 'submit jobs for job list testing' '
147136
cat active.ids > all.ids &&
148137
cat inactive.ids >> all.ids &&
149138
#
150-
# Synchronize all expected states
139+
# The job-list module has eventual consistency with the jobs stored in
140+
# the job-manager queue. To ensure no raciness in tests, ensure
141+
# jobs above have reached expected states in job-list before continuing.
151142
#
152-
job_list_wait_states
143+
flux job list-ids --wait-state=sched $(job_list_state_ids pending) &&
144+
flux job list-ids --wait-state=run $(job_list_state_ids running) &&
145+
flux job list-ids --wait-state=inactive $(job_list_state_ids inactive)
153146
'
154147

155148
# Note: "running" = "run" | "cleanup", we also test just "run" state
@@ -772,7 +765,7 @@ test_expect_success 'flux job list job state timing outputs valid (job inactive)
772765
test_expect_success 'flux job list job state timing outputs valid (job running)' '
773766
jobid=$(flux submit sleep 60 | flux job id) &&
774767
fj_wait_event $jobid start >/dev/null &&
775-
wait_jobid_state $jobid running &&
768+
wait_jobid_state $jobid run &&
776769
obj=$(flux job list -s running | grep $jobid) &&
777770
echo $obj | jq -e ".t_submit < .t_depend" &&
778771
echo $obj | jq -e ".t_depend < .t_run" &&

t/t2261-job-list-update.t

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,13 @@ test_expect_success 'submit jobs for job list testing' '
8181
cat active.ids > all.ids &&
8282
cat inactive.ids >> all.ids &&
8383
#
84-
# Synchronize all expected states
84+
# The job-list module has eventual consistency with the jobs stored in
85+
# the job-manager queue. To ensure no raciness in tests, ensure
86+
# jobs above have reached expected states in job-list before continuing.
8587
#
86-
job_list_wait_states
88+
flux job list-ids --wait-state=sched $(job_list_state_ids pending) &&
89+
flux job list-ids --wait-state=run $(job_list_state_ids running) &&
90+
flux job list-ids --wait-state=inactive $(job_list_state_ids inactive)
8791
'
8892

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

t/t2800-jobs-cmd.t

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,6 @@ runpty="${SHARNESS_TEST_SRCDIR}/scripts/runpty.py --line-buffer -f asciicast"
2323
# - running jobs - by start time (most recent first)
2424
# - inactive jobs - by completion time (most recent first)
2525
#
26-
# the job-list module has eventual consistency with the jobs stored in
27-
# the job-manager's queue. To ensure no raciness in tests, we spin
28-
# until all of the pending jobs have reached SCHED state, running jobs
29-
# have reached RUN state, and inactive jobs have reached INACTIVE
30-
# state.
31-
#
32-
33-
wait_states() {
34-
sched=$(job_list_state_count sched)
35-
run=$(job_list_state_count run)
36-
inactive=$(job_list_state_count inactive)
37-
local i=0
38-
printf >&2 "Waiting for sched=$sched run=$run inactive=$inactive\n"
39-
while ( [ "$(flux jobs -n --filter=sched | wc -l)" != "$sched" ] \
40-
|| [ "$(flux jobs -n --filter=run | wc -l)" != "$run" ] \
41-
|| [ "$(flux jobs -n --filter=inactive | wc -l)" != "$inactive" ]) \
42-
&& [ $i -lt 50 ]
43-
do
44-
sleep 0.1
45-
i=$((i + 1))
46-
done
47-
if [ "$i" -eq "50" ]; then
48-
return 1
49-
fi
50-
return 0
51-
}
5226

5327
export FLUX_PYCLI_LOGLEVEL=10
5428

@@ -159,8 +133,13 @@ test_expect_success 'submit jobs for job list testing' '
159133
tac inactiveids > inactive.ids &&
160134
cat inactive.ids active.ids >> all.ids &&
161135
#
162-
# Synchronize all expected states
163-
wait_states
136+
# The job-list module has eventual consistency with the jobs stored in
137+
# the job-manager queue. To ensure no raciness in tests, ensure
138+
# jobs above have reached expected states in job-list before continuing.
139+
#
140+
flux job list-ids --wait-state=sched $(job_list_state_ids sched) &&
141+
flux job list-ids --wait-state=run $(job_list_state_ids run) &&
142+
flux job list-ids --wait-state=inactive $(job_list_state_ids inactive)
164143
'
165144

166145
#

t/t2801-top-cmd.t

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,10 @@ export FLUX_URI_RESOLVE_LOCAL=t
1414

1515
# To ensure no raciness in tests below, ensure the job-list
1616
# module knows about submitted jobs in desired states
17-
JOB_WAIT_ITERS=100
1817
job_list_wait_state() {
1918
id=$1
20-
expected=$2
21-
local i=0
22-
while [ "$(flux jobs -no {state} ${id})" != "${expected}" ] \
23-
&& [ $i -lt ${JOB_WAIT_ITERS} ]
24-
do
25-
sleep 0.1
26-
i=$((i + 1))
27-
done
28-
if [ "$i" -eq "${JOB_WAIT_ITERS}" ]
29-
then
30-
return 1
31-
fi
32-
return 0
19+
state=$2
20+
flux job list-ids --wait-state=$2 $1 > /dev/null
3321
}
3422

3523
test_expect_success 'flux-top -h prints custom usage' '

0 commit comments

Comments
 (0)