Skip to content

Commit 89affb7

Browse files
committed
Add retries to the end-2-end tests.
This PR adds the ability to do a limited number of retries (3) for end2end tests. Often the windows tests will fail during CI (an error about the event loop being closed) crashing the whole end2end ci pipeline. As these are flaky, not broken, re-running the failed tests often fixes the problem. But this is annoying to have to get and email and click re-run each time it happens. This new version will rerun failed tests automatically, logging when a test that passed needed multiple tires. Hopefully this makes the windows issue less annoying going forward.
1 parent d93111e commit 89affb7

File tree

2 files changed

+55
-14
lines changed

2 files changed

+55
-14
lines changed

tests/end2end/runner.sh

+40-9
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,46 @@ source ./utils.sh
44

55
# Create an associated array mapping test name to exit code.
66
declare -A TESTS
7+
# Map testname to the number of times the test was run.
8+
declare -A RUNS
79

10+
TRIALS=3
11+
12+
# Each sub-directory in the current directory is a test.
813
for test in ./*/
914
do
15+
# Remove things like dir / from the test name
1016
testname="${test%*/}"
1117
testname="${testname#./}"
1218
yellow_echo "Running Test: ${testname}"
13-
echo "============================================================"
19+
echo "================================================================="
20+
# Move into the test dir
1421
pushd ${testname}
15-
if [[ -f ./clean.sh ]]; then
16-
./clean.sh
17-
else
18-
../clean.sh
19-
fi
20-
./test.sh
21-
TESTS[${testname}]=${?}
22+
# Run the test up to ${TRIALS} times, stopping when it has a return of 0
23+
i=0
24+
# This is just a non-zero value, just to get us into the loop, it doesn't
25+
# matter what the value is as it will be overwritten by the test return code.
26+
return_code=2
27+
while [[ "${i}" < "${TRIALS}" && ${return_code} != 0 ]]; do
28+
# If there is a local clean script run that, otherwise run the global one.
29+
# This is in the loop to ensure it is cleaned before each attempt.
30+
if [[ -f ./clean.sh ]]; then
31+
./clean.sh
32+
else
33+
../clean.sh
34+
fi
35+
if [[ "${i}" > 0 ]]; then
36+
red_echo "${testname} failed, running trial $((i + 1))"
37+
fi
38+
./test.sh
39+
return_code="${?}"
40+
i=$((i + 1))
41+
done
42+
# Save the tests return value
43+
TESTS[${testname}]="${return_code}"
44+
# Save the number of times a test had to be run.
45+
RUNS[${testname}]="${i}"
46+
# Cleanup after the test, again, look for a local clean and use if found.
2247
if [[ -f ./clean.sh ]]; then
2348
./clean.sh
2449
else
@@ -32,7 +57,13 @@ echo "Test Summary:"
3257
for test in "${!TESTS[@]}"
3358
do
3459
if [[ "${TESTS[$test]}" == 0 ]]; then
35-
green_echo "${test}"
60+
green_echo "${test}" "n"
61+
# Check if we had to re-run tests.
62+
if [[ "${RUNS[$test]}" != 1 ]]; then
63+
yellow_echo " (Had to run test '${test}' ${RUNS[$test]} times to pass)."
64+
else
65+
echo
66+
fi
3667
else
3768
red_echo "${test}"
3869
fi

tests/end2end/utils.sh

+15-5
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,37 @@ NORMAL="\033[0m"
99
function color_echo {
1010
local text="${1}"
1111
local color="${2}"
12-
echo -e "${color}${text}${NORMAL}"
12+
local newline="${3}"
13+
# If we provide a 3rd argument, don't include the newline, this lets us
14+
# do two colors on one line easily.
15+
if [[ -z "${newline}" ]]; then
16+
echo -e "${color}${text}${NORMAL}"
17+
else
18+
echo -en "${color}${text}${NORMAL}"
19+
fi
1320
}
1421

1522
function green_echo {
1623
local text="${1}"
17-
color_echo "${text}" "${GREEN}"
24+
local newline="${2}"
25+
color_echo "${text}" "${GREEN}" "${newline}"
1826
}
1927

2028
function red_echo {
2129
local text="${1}"
22-
color_echo "${text}" "${RED}"
30+
local newline="${2}"
31+
color_echo "${text}" "${RED}" "${newline}"
2332
}
2433

2534
function yellow_echo {
2635
local text="${1}"
27-
color_echo "${text}" "${YELLOW}"
36+
local newline="${2}"
37+
color_echo "${text}" "${YELLOW}" "${newline}"
2838
}
2939

3040
function make_repo {
3141
echo "Making Git Repo."
32-
git init
42+
git init 2> /dev/null
3343
git branch -m main
3444
# Set the git user/email for the generated test repo
3545
git config --local user.email "[email protected]"

0 commit comments

Comments
 (0)