Merge pull request #128 from cmeury/retry-curl
retry curl to reduce risk of race condition
This commit is contained in:
commit
67ddd7f1ae
|
|
@ -20,21 +20,33 @@ kubectl="kubectl --context=minikube --namespace=${test_ns}"
|
||||||
# FUNCTIONS ----------------------------------------------------------------------------------------------------------
|
# FUNCTIONS ----------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
function wait_deploy_ready() {
|
function wait_deploy_ready() {
|
||||||
$kubectl rollout status deployment ${1}
|
${kubectl} rollout status deployment ${1}
|
||||||
while [ "$($kubectl get deploy ${1} -o=jsonpath='{.status.readyReplicas}')" == "0" ]; do
|
while [ "$(${kubectl} get deploy ${1} -o=jsonpath='{.status.readyReplicas}')" == "0" ]; do
|
||||||
info "Waiting for deployment ${1} to be ready"
|
info "Waiting for deployment ${1} to be ready"
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
function retry() {
|
||||||
|
local -r max=${1}
|
||||||
|
local -r command=${2}
|
||||||
|
n=0
|
||||||
|
retry_result=0
|
||||||
|
until [ ${n} -ge ${max} ]; do
|
||||||
|
info "Executing: ${command} (attempt $((n+1)))"
|
||||||
|
${command} && break # substitute your command here
|
||||||
|
retry_result=$?
|
||||||
|
n=$[$n+1]
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# SETUP --------------------------------------------------------------------------------------------------------------
|
# SETUP --------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
info "Using namespace: ${test_ns}"
|
info "Using namespace: ${test_ns}"
|
||||||
info "Using Helm version: $(helm version --short --client | grep -o v.*$)"
|
info "Using Helm version: $(helm version --short --client | grep -o v.*$)"
|
||||||
$helm init --wait --override spec.template.spec.automountServiceAccountToken=true
|
${helm} init --wait --override spec.template.spec.automountServiceAccountToken=true
|
||||||
$helmfile -v
|
${kubectl} get namespace ${test_ns} &> /dev/null && warn "Namespace ${test_ns} exists, from a previous test run?"
|
||||||
$kubectl get namespace ${test_ns} &> /dev/null && warn "Namespace ${test_ns} exists, from a previous test run?"
|
|
||||||
$kubectl create namespace ${test_ns} || fail "Could not create namespace ${test_ns}"
|
$kubectl create namespace ${test_ns} || fail "Could not create namespace ${test_ns}"
|
||||||
trap "{ $kubectl delete namespace ${test_ns}; }" EXIT # remove namespace whenever we exit this script
|
trap "{ $kubectl delete namespace ${test_ns}; }" EXIT # remove namespace whenever we exit this script
|
||||||
|
|
||||||
|
|
@ -42,13 +54,14 @@ trap "{ $kubectl delete namespace ${test_ns}; }" EXIT # remove namespace wheneve
|
||||||
# TEST CASES----------------------------------------------------------------------------------------------------------
|
# TEST CASES----------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
test_start "happypath - simple rollout of httpbin chart"
|
test_start "happypath - simple rollout of httpbin chart"
|
||||||
$helmfile -f ${dir}/happypath.yaml sync
|
info "Syncing ${dir}/happypath.yaml"
|
||||||
|
${helmfile} -f ${dir}/happypath.yaml sync
|
||||||
wait_deploy_ready httpbin-httpbin
|
wait_deploy_ready httpbin-httpbin
|
||||||
curl --fail $(minikube service --url --namespace=${test_ns} httpbin-httpbin)/status/200 \
|
retry 3 "curl --fail $(minikube service --url --namespace=${test_ns} httpbin-httpbin)/status/200"
|
||||||
|| fail "httpbin failed to return 200 OK"
|
[ ${retry_result} -eq 0 ] || fail "httpbin failed to return 200 OK"
|
||||||
$helmfile -f ${dir}/happypath.yaml delete
|
info "Deleting release"
|
||||||
$helm status --namespace=${test_ns} httpbin &> /dev/null \
|
${helmfile} -f ${dir}/happypath.yaml delete
|
||||||
&& fail "release should not exist anymore after a delete"
|
${helm} status --namespace=${test_ns} httpbin &> /dev/null && fail "release should not exist anymore after a delete"
|
||||||
test_pass "happypath"
|
test_pass "happypath"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue