Skip to content

Commit

Permalink
Add ignore_error_attempts argument to ct_test_response so the functio…
Browse files Browse the repository at this point in the history
…n does not end before container is properly initialized
  • Loading branch information
hhorak committed Dec 19, 2017
1 parent f510718 commit 37f8907
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,14 @@ function ct_obtain_input() {
# Argument: url - request URL path
# Argument: expected_code - expected HTTP response code
# Argument: body_regexp - PCRE regular expression that must match the response body
# Argument: max_attempts - Optional number of attempts (default: 20), one second sleep between
# Argument: max_attempts - Optional number of attempts (default: 20), three seconds sleep between
# Argument: ignore_error_attempts - Optional number of attempts when we ignore error output (default: 10)
ct_test_response() {
local url="$1"
local expected_code="$2"
local body_regexp="$3"
local max_attempts=${4:-20}
local ignore_error_attempts=${5:-10}

: " Testing the HTTP(S) response for <${url}>"
local sleep_time=3
Expand All @@ -324,7 +326,12 @@ ct_test_response() {
result=0
fi
cat ${response_file} | grep -qP -e "${body_regexp}" || result=1;
break
# Some services return 40x code until they are ready, so let's give them
# some chance and not end with failure right away
# Do not wait if we already have expected outcome though
if [ ${result} -eq 0 -o ${attempt} -gt ${ignore_error_attempts} -o ${attempt} -eq ${max_attempts} ] ; then
break
fi
fi
attempt=$(( ${attempt} + 1 ))
sleep ${sleep_time}
Expand Down

0 comments on commit 37f8907

Please sign in to comment.