Skip to content

Commit 8a22d33

Browse files
committed
CI: Build and retry 3 times with Random Exponential Backoff
Build and retry 3 times with Random Exponential Backoff. Signed-off-by: Lup Yuen Lee <luppy@appkaki.com>
1 parent 8323456 commit 8a22d33

1 file changed

Lines changed: 46 additions & 2 deletions

File tree

tools/testbuild.sh

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ nuttx=$WD/../nuttx
2424

2525
progname=$0
2626
fail=0
27+
maxbuilds=4 # Retry 3 times on failure
2728
APPSDIR=$WD/../apps
2829
if [ -z $ARTIFACTDIR ]; then
2930
ARTIFACTDIR=$WD/../buildartifacts
@@ -580,6 +581,49 @@ function dotest {
580581
fi
581582
}
582583

584+
# Build one entry from the test list file. Retry on failure.
585+
function retrytest {
586+
# Remember the Fail Status and clear it for each build
587+
local line=$1
588+
local prevfail=$fail
589+
local backoff=60 # Initial Exponential Backoff, in seconds
590+
591+
# Build and retry on failure, with Random Exponential Backoff
592+
for ((i = 1; i <= $maxbuilds; i++)); do
593+
echo "Build Attempt $i of $maxbuilds"
594+
fail=0
595+
dotest $line
596+
597+
# Don't retry if the build succeeded
598+
if [ ${fail} -eq 0 ]; then
599+
break
600+
else
601+
# Build Failed: Clean up any corrupted downloads, don't reuse
602+
git -C $nuttx clean -fd
603+
git -C $APPSDIR clean -fd
604+
pushd $nuttx ; git status ; popd
605+
pushd $APPSDIR ; git status ; popd
606+
fi
607+
608+
# If this is Final Retry: Don't retry subsequent builds
609+
if [ $i -eq $maxbuilds ]; then
610+
maxbuilds=1
611+
break
612+
fi
613+
614+
# Wait for Random Exponential Backoff, then retry
615+
delay=$(( (RANDOM % $backoff) + 1 ))
616+
echo "Wait $delay seconds ($backoff backoff)"
617+
backoff=$(($backoff * 2))
618+
sleep $delay
619+
done
620+
621+
# Return the Previous Fail Status, unless this build failed
622+
if [ ${fail} -eq 0 ]; then
623+
fail=$prevfail
624+
fi
625+
}
626+
583627
# Perform the build test for each entry in the test list file
584628

585629
for line in $testlist; do
@@ -588,10 +632,10 @@ for line in $testlist; do
588632
dir=`echo $line | cut -d',' -f1`
589633
list=`find boards$dir -name defconfig | cut -d'/' -f4,6`
590634
for i in ${list}; do
591-
dotest $i${line/"$dir"/}
635+
retrytest $i${line/"$dir"/}
592636
done
593637
else
594-
dotest $line
638+
retrytest $line
595639
fi
596640
done
597641

0 commit comments

Comments
 (0)