Files
dokku/tests/unit/proxy-route-traefik.bats
T
Jose Diaz-Gonzalez 6dbd9b4d82 fix: make T3 route-removal assertions robust to reload race
T3 in every per-backend file polled the post-removal HTTP response using assert_http_localhost_response_contains, which retries on status code only. After a route is removed, both api and web return 200 for /api/v0/Procfile so the polling exits immediately; the body check then races with the proxy daemon picking up the new state and observes api's response (Procfile content) instead of web's catch-all. The proxy:route:remove output was also unechoed, hiding whether BuildConfig actually fired or was no-op suppressed. Each T3 now echoes the remove output and status, asserts via proxy:route:report that storage was cleared, then polls the body in a hand-rolled retry loop until the api marker is no longer present (timeout 30s). The k3s T3 files similarly retry the kubectl probe so the chart re-render has time to settle.
2026-11-04 14:56:38 -05:00

137 lines
4.5 KiB
Bash

#!/usr/bin/env bats
load test_helper
setup() {
global_setup
dokku nginx:stop
dokku traefik:start
create_app
dokku proxy:set "$TEST_APP" traefik
}
teardown() {
dokku proxy:route:clear "$TEST_APP" >/dev/null 2>&1 || true
destroy_app
dokku traefik:stop
dokku nginx:start
global_teardown
}
@test "(proxy-route:traefik) basic routing - /api/v0 hits api, / hits web" {
run deploy_app python "dokku@$DOKKU_DOMAIN:$TEST_APP" add_api_process_callback
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:scale $TEST_APP web=1 api=1"
assert_success
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001"
echo "output: $output"
echo "status: $status"
assert_success
# Routes are applied via container labels - rebuild so the api container
# restarts with the new labels attached.
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
# Without --strip-prefix, /api/v0/Procfile reaches api as /api/v0/Procfile
# which python's http.server returns 404 for. A 404 here proves the route
# reaches api - web's catch-all would have returned 200.
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "" "404"
}
@test "(proxy-route:traefik) --strip-prefix toggles upstream path visibility" {
run deploy_app python "dokku@$DOKKU_DOMAIN:$TEST_APP" add_api_process_callback
assert_success
run /bin/bash -c "dokku ps:scale $TEST_APP web=1 api=1"
assert_success
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "" "404"
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001 --strip-prefix"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "python3 -m http.server"
}
@test "(proxy-route:traefik) removing a route falls back to web" {
run deploy_app python "dokku@$DOKKU_DOMAIN:$TEST_APP" add_api_process_callback
assert_success
run /bin/bash -c "dokku ps:scale $TEST_APP web=1 api=1"
assert_success
# Set the route without --strip-prefix first; a 404 from api proves the
# labels attached and traefik is routing correctly.
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "" "404"
# Switch to --strip-prefix and verify api now serves the Procfile.
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001 --strip-prefix"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "python3 -m http.server"
run /bin/bash -c "dokku proxy:route:remove $TEST_APP /api/v0"
echo "output: $output"
echo "status: $status"
assert_success
# Confirm storage was actually mutated before doing the slow rebuild.
run /bin/bash -c "dokku proxy:route:report $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "(none)"
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
# After ps:rebuild, traefik recreates the api container without the route
# labels, but there is still a race with traefik picking up the new state.
# Hand-roll a retry that polls the BODY until api's marker is gone.
local body=""
for attempt in $(seq 1 30); do
run curl --connect-to "${TEST_APP}.${DOKKU_DOMAIN}:80:localhost:80" -kSs "http://${TEST_APP}.${DOKKU_DOMAIN}:80/api/v0/Procfile"
body="$output"
if ! grep -q 'python3 -m http.server' <<<"$body"; then
break
fi
sleep 1
done
echo "final body attempt $attempt: $body"
run /bin/bash -c "grep -c 'python3 -m http.server' <<<\"$body\" || true"
assert_output "0"
}
add_api_process_callback() {
local APP="$1"
local APP_REPO_DIR="$2"
echo "api: python3 -m http.server 5001" >>"$APP_REPO_DIR/Procfile"
}