Skip to content

Commit

Permalink
Use incremental backoff instead of hardcoding fixed sleep times
Browse files Browse the repository at this point in the history
With fixed/long sleep times, tests run slower when there is no need to
wait for that long. When the machine is slow (or under heavy load), we
often to need to wait for longer before things are running and the fixed
sleep times are not sufficient.
  • Loading branch information
omajid committed Feb 7, 2024
1 parent e480081 commit b7de427
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
7 changes: 2 additions & 5 deletions dotnet-monitor-works/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ dotnet tool update -g dotnet-monitor --version "${VERSION_SPLIT[0]}.*-*"
export PATH="$HOME/.dotnet/tools:$PATH"

dotnet-monitor collect --no-auth &
sleep 5
indexhttps=$(wget --no-check-certificate -O https.html https://127.0.0.1:52323/info)
../run-until-success-with-backoff wget --no-check-certificate -O https.html https://127.0.0.1:52323/info

https=$(cat https.html)

if [[ $https == *"version"* ]]; then
sleep 5
echo "collect - OK"
else
sleep 5
pkill dotnet-monitor
rm "https.html"
echo "collect - FAIL"
Expand All @@ -45,4 +42,4 @@ else
echo "generatekey - FAIL"
pkill dotnet-monitor
exit 1
fi
fi
4 changes: 1 addition & 3 deletions libuv-kestrel-sample-app-2x/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ dotnet build
dotnet bin/Debug/netcoreapp*/libuv-kestrel-sample-app-2x.dll &
root_pid=$!

sleep 5

curl "http://localhost:5000"
../run-until-success-with-backoff curl "http://localhost:5000"

kill -s SIGTERM "${root_pid}"
sleep 1
Expand Down
5 changes: 2 additions & 3 deletions publish-aspnet-selfcontained/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ ASPNETCORE_URLS="$url" "./$output_dir/web" &
run_pid=$!
trap "kill $run_pid && wait $run_pid" EXIT

sleep 5

if ! curl "$url"; then
if ! ../run-until-success-with-backoff curl "$url" ; then
echo 'FAIL: ASP.NET app failed to respond'
exit 2
fi

echo "PASS"
echo "PASS"
16 changes: 16 additions & 0 deletions run-until-success-with-backoff
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -euo pipefail

set -x

i=0
max_retries=20
until "$@"; do
((i+=1))
if [[ $i == "$max_retries" ]]; then
echo "$@" "still failing after $max_retries retries"
exit 1
fi
sleep $i
done

0 comments on commit b7de427

Please sign in to comment.