fix: deflake haproxy bats tests
The byjg/easy-haproxy image polls Docker for label changes every 10 seconds by default, which races with the haproxy bats suite and intermittently produces curl exit 7. Expose `refresh-conf` as a global-only haproxy property that maps to `EASYHAPROXY_REFRESH_CONF`, lower it to 2 seconds in the bats setup, and wrap the localhost HTTP assertions in a retry loop so checks wait for haproxy to converge rather than failing on the first attempt.
This commit is contained in:
7 files changed
+81
-13
No files matched your search
+39
-7
@@ -7,6 +7,7 @@ setup() {
|
||||
dokku nginx:stop
|
||||
dokku haproxy:set --global letsencrypt-server https://acme-staging-v02.api.letsencrypt.org/directory
|
||||
dokku haproxy:set --global letsencrypt-email
|
||||
dokku haproxy:set --global refresh-conf 2
|
||||
dokku haproxy:start
|
||||
create_app
|
||||
}
|
||||
@@ -15,6 +16,7 @@ teardown() {
|
||||
global_teardown
|
||||
destroy_app
|
||||
dokku haproxy:stop
|
||||
dokku haproxy:set --global refresh-conf
|
||||
dokku nginx:start
|
||||
}
|
||||
|
||||
@@ -32,6 +34,42 @@ teardown() {
|
||||
assert_output "$help_output"
|
||||
}
|
||||
|
||||
@test "(haproxy) refresh-conf" {
|
||||
run /bin/bash -c "dokku haproxy:set $TEST_APP refresh-conf 2"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_failure
|
||||
assert_output_contains "can only be set globally"
|
||||
|
||||
run /bin/bash -c "dokku haproxy:set --global refresh-conf 5"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku haproxy:report --global --haproxy-refresh-conf"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "5"
|
||||
|
||||
run /bin/bash -c "dokku haproxy:show-config"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "EASYHAPROXY_REFRESH_CONF=5"
|
||||
|
||||
run /bin/bash -c "dokku haproxy:set --global refresh-conf"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku haproxy:report --global --haproxy-refresh-conf"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "10"
|
||||
}
|
||||
|
||||
@test "(haproxy) log-level" {
|
||||
run /bin/bash -c "dokku haproxy:set --global log-level DEBUG"
|
||||
echo "output: $output"
|
||||
@@ -60,11 +98,7 @@ teardown() {
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "curl --silent $(dokku url $TEST_APP)"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "python/http.server"
|
||||
assert_http_localhost_response_contains "http" "$TEST_APP.$DOKKU_DOMAIN" "80" "/" "python/http.server"
|
||||
}
|
||||
|
||||
@test "(haproxy) multiple domains" {
|
||||
@@ -88,8 +122,6 @@ teardown() {
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
sleep 5
|
||||
|
||||
run /bin/bash -c "dokku logs $TEST_APP"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
|
||||
@@ -249,10 +249,17 @@ assert_http_success() {
|
||||
|
||||
assert_http_localhost_response() {
|
||||
local scheme="$1" domain="$2" port="${3:-80}" path="${4:-}" content="${5:-}" status_code="${6:-200}"
|
||||
run curl --connect-to "$domain:$port:localhost:$port" -kSso /dev/null -w "%{http_code}" "$scheme://$domain:$port$path"
|
||||
local retries="${HTTP_ASSERT_RETRIES:-30}" attempt=1
|
||||
while [[ "$attempt" -lt "$retries" ]]; do
|
||||
run curl --connect-to "$domain:$port:localhost:$port" -kSso /dev/null -w "%{http_code}" "$scheme://$domain:$port$path"
|
||||
[[ "$output" == "$status_code" ]] && break
|
||||
sleep 1
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
echo "curl: curl --connect-to $domain:$port:localhost:$port -kSso /dev/null -w %{http_code} $scheme://$domain:$port$path"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
echo "attempts: $attempt"
|
||||
assert_output "$status_code"
|
||||
|
||||
if [[ -n "$content" ]]; then
|
||||
@@ -265,10 +272,17 @@ assert_http_localhost_response() {
|
||||
|
||||
assert_http_localhost_response_contains() {
|
||||
local scheme="$1" domain="$2" port="${3:-80}" path="${4:-}" content="${5:-}" status_code="${6:-200}"
|
||||
run curl --connect-to "$domain:$port:localhost:$port" -kSso /dev/null -w "%{http_code}" "$scheme://$domain:$port$path"
|
||||
local retries="${HTTP_ASSERT_RETRIES:-30}" attempt=1
|
||||
while [[ "$attempt" -lt "$retries" ]]; do
|
||||
run curl --connect-to "$domain:$port:localhost:$port" -kSso /dev/null -w "%{http_code}" "$scheme://$domain:$port$path"
|
||||
[[ "$output" == "$status_code" ]] && break
|
||||
sleep 1
|
||||
attempt=$((attempt + 1))
|
||||
done
|
||||
echo "curl: curl --connect-to $domain:$port:localhost:$port -kSso /dev/null -w %{http_code} $scheme://$domain:$port$path"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
echo "attempts: $attempt"
|
||||
assert_output "$status_code"
|
||||
|
||||
if [[ -n "$content" ]]; then
|
||||
|
||||
Reference in new issue
Block a user