Skip to content

Commit cfbb87c

Browse files
authored
ci: retry testmo requests (#9727)
1 parent 31a439a commit cfbb87c

File tree

3 files changed

+76
-7
lines changed

3 files changed

+76
-7
lines changed

.github/actions/test_ya/action.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ runs:
101101
shell: bash
102102
run: |
103103
set -x
104-
104+
105+
echo "$(pwd)/ydb/ci/scripts" >> $GITHUB_PATH
106+
105107
export TMP_DIR=$(pwd)/tmp
106108
rm -rf $TMP_DIR
107109
mkdir -p $TMP_DIR
@@ -356,7 +358,7 @@ runs:
356358
TESTMO_TOKEN=${{ inputs.testman_token }} testmo automation:resources:add-link --name build --url "$TESTMO_RUN_URL" --resources $CURRENT_PUBLIC_DIR/testmo.json
357359
TESTMO_TOKEN=${{ inputs.testman_token }} testmo automation:resources:add-field --name git-sha --type string --value "${GITHUB_SHA:0:7}" --resources $CURRENT_PUBLIC_DIR/testmo.json
358360
TESTMO_RUN_ID=$(
359-
TESTMO_TOKEN=${{ inputs.testman_token }} testmo automation:run:create --instance "https://$TESTMO_PROXY_ADDR" --project-id ${{ inputs.testman_project_id }} \
361+
TESTMO_TOKEN=${{ inputs.testman_token }} retry.sh -- testmo automation:run:create --instance "https://$TESTMO_PROXY_ADDR" --project-id ${{ inputs.testman_project_id }} \
360362
--name "$TESTMO_RUN_NAME" --source "$TESTMO_SOURCE" --resources $CURRENT_PUBLIC_DIR/testmo.json \
361363
--tags "$TESTMO_BRANCH_TAG" --tags "$TESTMO_EXTRA_TAG"
362364
)
@@ -471,11 +473,11 @@ runs:
471473
# archive unitest reports (transformed)
472474
tar -C $TESTMO_JUNIT_REPORT_PARTS/.. -czf $PUBLIC_DIR/junit_parts.xml.tar.gz $(basename $TESTMO_JUNIT_REPORT_PARTS)
473475

474-
TESTMO_TOKEN=${{ inputs.testman_token }} testmo automation:run:submit-thread \
476+
TESTMO_TOKEN=${{ inputs.testman_token }} retry.sh -- testmo automation:run:submit-thread \
475477
--instance "https://$TESTMO_PROXY_ADDR" --run-id "$TESTMO_RUN_ID" \
476478
--results "$TESTMO_JUNIT_REPORT_PARTS/*.xml"
477479

478-
TESTMO_TOKEN=${{ inputs.testman_token }} testmo automation:run:complete --instance "https://$TESTMO_PROXY_ADDR" --run-id $TESTMO_RUN_ID || true
480+
TESTMO_TOKEN=${{ inputs.testman_token }} retry.sh -- testmo automation:run:complete --instance "https://$TESTMO_PROXY_ADDR" --run-id $TESTMO_RUN_ID || true
479481
echo "runid=" >> $GITHUB_OUTPUT
480482
fi
481483

@@ -512,7 +514,7 @@ runs:
512514
shell: bash
513515
run: |
514516
if [ ${{ steps.build.outputs.runid }} ]; then
515-
TESTMO_TOKEN=${{ inputs.testman_token }} testmo automation:run:complete --instance "https://$TESTMO_PROXY_ADDR" --run-id ${{ steps.build.outputs.runid }} || true
517+
TESTMO_TOKEN=${{ inputs.testman_token }} retry.sh -- testmo automation:run:complete --instance "https://$TESTMO_PROXY_ADDR" --run-id ${{ steps.build.outputs.runid }} || true
516518
fi
517519
if [ ${{ inputs.testman_token }} ]; then
518520
kill $TESTMO_PROXY_PID

ydb/ci/scripts/retry.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
3+
usage() {
4+
echo "$0 -r [max_attempts] -t [timeout] -s [sleep] -- cmd"
5+
}
6+
if [ $# -lt 2 ]; then
7+
usage
8+
exit 1
9+
fi
10+
11+
max_attempts=0
12+
timeout=1800
13+
sleep_time=30
14+
15+
while getopts 'r:t:s:' opt; do
16+
case "$opt" in
17+
r)
18+
max_attempts=$OPTARG
19+
;;
20+
t)
21+
timeout=$OPTARG
22+
;;
23+
s)
24+
sleep_time=$OPTARG
25+
;;
26+
*)
27+
usage
28+
exit 1
29+
;;
30+
esac
31+
done
32+
33+
34+
shift $((OPTIND - 2))
35+
36+
if [[ "$1" == "--" ]]; then
37+
shift # Shift past the double dash
38+
else
39+
echo "Error: Missing -- before command"
40+
exit 1
41+
fi
42+
43+
attempt_num=1
44+
start_time=$(date +%s)
45+
46+
while true; do
47+
elapsed=$(($(date +%s) - start_time))
48+
49+
if [ "$max_attempts" -ne 0 ] && [ "$attempt_num" -ge "$max_attempts" ]; then
50+
echo "maximum attempts reached, exit" >&2
51+
exit 10
52+
fi
53+
54+
if [ "$timeout" -ne 0 ] && [ $elapsed -ge "$timeout" ]; then
55+
echo "timeout reached, exit" >&2
56+
exit 11
57+
fi
58+
59+
if "$@"; then
60+
exit
61+
else
62+
attempt_num=$(( attempt_num + 1 ))
63+
if [ "$sleep_time" != "0" ]; then
64+
sleep "$sleep_time"
65+
fi
66+
fi
67+
done

ydb/ci/testmo-proxy/testmo-proxy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ class Handler(http.server.BaseHTTPRequestHandler):
1515
error_message_format = '{"status":"error", "code":"%(code)d", "message": "%(message)s"}\n'
1616

1717
# noinspection PyMissingConstructor
18-
def __init__(self, target_url: str, timeout: Tuple[int, int], max_reqest_time: int):
18+
def __init__(self, target_url: str, timeout: Tuple[int, int], max_request_time: int):
1919
self._target_url = target_url
2020
self._timeout = timeout
21-
self._max_request_time = max_reqest_time
21+
self._max_request_time = max_request_time
2222

2323
def __call__(self, *args, **kwargs):
2424
super().__init__(*args, **kwargs)

0 commit comments

Comments
 (0)