Skip to content

Commit 7379bbd

Browse files
committed
Do API health check before running tests
1 parent b7f7486 commit 7379bbd

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

test/integration/test_api.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ assertHttpRequestEquals() {
7171

7272
if [ "${expected_response_code}" != "${actual_response_code}" ]; then
7373
e "Response code didn't match expectation. Request [${method} ${uri}] Expected [${expected_response_code}] Actual [${actual_response_code}]"
74-
e "curl command: ${curl_cmd} -s -o /dev/null -w '%{http_code}' '${uri}'"
74+
e "curl command: ${curl_cmd} -s -o /dev/null -w '%{http_code}' --head '${uri}'"
7575
exit ${test_fail_exit_code}
7676
fi
7777
elif [ "${method}" = "GET" ]; then
@@ -104,6 +104,21 @@ assertHttpRequestEquals() {
104104
fi
105105
}
106106

107+
# Check to see if HTTP server is available
108+
set +o errexit
109+
# Allow curl command to fail with a non-zero exit code for this block because
110+
# we want to use it to test to see if the server is actually up.
111+
for (( i=1; i<=3; i++ )); do
112+
response="$(${curl_cmd} -s -o /dev/null -w '%{http_code}' --head "${test_server}")"
113+
if [ "${response}" != "000" ]; then
114+
break
115+
fi
116+
wait_time="$((i * 2))"
117+
e "Failed to access ${test_server} - trying again in ${wait_time} seconds, try ${i}/3"
118+
sleep ${wait_time}
119+
done
120+
set -o errexit
121+
107122
# Ordinary filenames
108123

109124
assertHttpRequestEquals "HEAD" "a.txt" "200"

0 commit comments

Comments
 (0)