Skip to content

Commit

Permalink
Merge pull request #173 from Martchus/investigate
Browse files Browse the repository at this point in the history
Postpone investigation jobs only if pending jobs are in same cluster
  • Loading branch information
mergify[bot] committed Jul 14, 2022
2 parents fbd5f95 + 38a19b4 commit 64352ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 5 additions & 3 deletions openqa-investigate
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,16 @@ trigger_jobs() {
}

query_dependency_data_or_postpone() {
local id=$1 job_data=$2 dependency_data pending_cluster_jobs
local id=$1 job_data=$2 dependency_data pending_cluster_jobs cluster_jobs

# postpone if not all dependencies are done/cancelled
# note: This "AJAX" route is normally used to render the dependencies tab in the web UI.
dependency_data=$(openqa-cli "${client_args[@]}" --apibase '' --json tests/"$id"/dependencies_ajax)
pending_cluster_jobs=$(echo "$dependency_data" | runjq -r '[.nodes[] | select(.state != "done" and .state != "cancelled")] | length') || return $?
cluster_jobs=$(echo "$dependency_data" | runjq -r "[$id, [.cluster[] | select(contains([$id]))]] | flatten | unique") || return $?
# shellcheck disable=SC2016
pending_cluster_jobs=$(echo "$dependency_data" | runjq --argjson cluster_jobs "$cluster_jobs" -r '[.nodes[] | select([.id] | inside($cluster_jobs)) | select([.state] | inside(["done", "cancelled"]) | not)] | length') || return $?
[[ $pending_cluster_jobs != 0 ]] \
&& echoerr "Postponing to investigate job $id: waiting until pending dependencies have finished" && return 142
&& echoerr "Postponing to investigate job $id: waiting until $pending_cluster_jobs pending parallel job(s) finished" && return 142

# do not skip the job
echo "$dependency_data"
Expand Down
12 changes: 9 additions & 3 deletions test/02-investigate.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PATH=$BASHLIB$PATH

source bash+ :std
use Test::More
plan tests 26
plan tests 27

host=localhost
url=https://localhost
Expand Down Expand Up @@ -65,6 +65,8 @@ openqa-cli() {
echo '{"cluster":{"cluster_foo":[28],"cluster_bar":[29]}, "edges":[], "nodes":[{"id":28,"state":"done","result":"failed"},{"id":29,"state":"done","result":"passed"}]}'
elif [[ $@ == '--apibase --json tests/30/dependencies_ajax' ]]; then
echo '{"cluster":{"cluster_foo":[28,30],"cluster_bar":[29]}, "edges":[], "nodes":[{"id":28,"state":"uploading","result":"none"},{"id":30,"state":"done","result":"passed"}]}'
elif [[ $@ == '--apibase --json tests/32/dependencies_ajax' ]]; then
echo '{"cluster":{"cluster_foo":[28,32],"cluster_bar":[29]}, "edges":[], "nodes":[{"id":28,"state":"cancelled","result":"none"},{"id":32,"state":"done","result":"failed"},{"id":29,"state":"running","result":"running"}]}'
elif [[ $@ == '--apibase --json tests/31/dependencies_ajax' ]]; then
# job with cancelled job in the cluster (should be treated like a done job)
echo '{"cluster":{"cluster_foo":[28,31],"cluster_bar":[29]}, "edges":[], "nodes":[{"id":28,"state":"cancelled","result":"none"},{"id":31,"state":"done","result":"failed"}]}'
Expand Down Expand Up @@ -93,12 +95,16 @@ like "$out" "exclude_no_group is set, skipping investigation"
rc=0
out=$(investigate 30 2>&1) || rc=$?
is "$rc" 142 'investigation postponed because other job in cluster is not done'
like "$out" "Postponing to investigate job 30: waiting until pending dependencies have finished"
is "$out" "Postponing to investigate job 30: waiting until 1 pending parallel job(s) finished"

rc=0
out=$(echo 30 | main 2>&1) || rc=$?
is "$rc" 142 'return code (for postponing) passed by main function'
like "$out" "Postponing to investigate job 30: waiting until pending dependencies have finished" 'output passed by main function'
is "$out" "Postponing to investigate job 30: waiting until 1 pending parallel job(s) finished" 'output passed by main function'

rc=0
out=$(investigate 32 2>&1) || rc=$?
is "$rc" 0 'investigation not postponed if other job in dependency tree not done but cluster itself is done'

rc=0
out=$(force=true investigate 31 2>&1) || rc=$?
Expand Down

0 comments on commit 64352ee

Please sign in to comment.