From 2d26d353ceaca7878bb222684e5d1d144a95d1f5 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Fri, 9 Jan 2026 11:17:38 +0100 Subject: [PATCH] REGTESTS: add test on backend switching rules selection Create a new test to ensure that switching rules selection is fine. Currently, this checks that dynamic backend switching works as expected. If a matching rule is resolved to an unexisting backend, the default backend is used instead. This regtest should be useful as switching-rules will be extended in a future set of patches to add new abilities on backends, linked to dynamic backend support. --- reg-tests/stream/test_content_switching.vtc | 98 +++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 reg-tests/stream/test_content_switching.vtc diff --git a/reg-tests/stream/test_content_switching.vtc b/reg-tests/stream/test_content_switching.vtc new file mode 100644 index 000000000..d580ed0cc --- /dev/null +++ b/reg-tests/stream/test_content_switching.vtc @@ -0,0 +1,98 @@ +varnishtest "Ensure switching-rules conformance with backend eligibility" + +feature ignore_unknown_macro + +haproxy hsrv -conf { + global + .if feature(THREAD) + thread-groups 1 + .endif + + defaults + mode http + timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" + timeout client "${HAPROXY_TEST_TIMEOUT-5s}" + timeout server "${HAPROXY_TEST_TIMEOUT-5s}" + + frontend fe + bind "fd@${feS}" + http-request return status 200 hdr "x-be" "li" +} -start + +haproxy h1 -conf { + global + .if feature(THREAD) + thread-groups 1 + .endif + + defaults + mode http + timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" + timeout client "${HAPROXY_TEST_TIMEOUT-5s}" + timeout server "${HAPROXY_TEST_TIMEOUT-5s}" + + frontend fe + bind "fd@${fe1S}" + use_backend %[req.hdr("x-target")] if { req.hdr("x-dyn") "1" } + + frontend fe_default + bind "fd@${fe2S}" + + use_backend %[req.hdr("x-target")] if { req.hdr("x-dyn") "1" } + use_backend be + default_backend be_default + + listen li + bind "fd@${liS}" + use_backend %[req.hdr("x-target")] if { req.hdr("x-dyn") "1" } + server srv ${hsrv_feS_sock} + + backend be + http-request return status 200 hdr "x-be" %[be_name] + + backend be_default + http-request return status 200 hdr "x-be" %[be_name] +} -start + +client c1 -connect ${h1_fe1S_sock} { + # Dynamic rule matching + txreq -hdr "x-dyn: 1" -hdr "x-target: be" + rxresp + expect resp.status == 200 + expect resp.http.x-be == "be" + + # Dynamic rule no match -> 503 expected + txreq -hdr "x-dyn: 1" -hdr "x-target: be_unknown" + rxresp + expect resp.status == 503 +} -run + +# Connect to frontend with default backend set +client c2 -connect ${h1_fe2S_sock} { + # Dynamic rule matching + txreq -hdr "x-dyn: 1" -hdr "x-target: be" + rxresp + expect resp.status == 200 + expect resp.http.x-be == "be" + + # Dynamic rule no match -> use default backend + txreq -hdr "x-dyn: 1" -hdr "x-target: be_unknown" + rxresp + expect resp.status == 200 + expect resp.http.x-be == "be_default" +} -run + +# Connect to listen proxy type +client c3 -connect ${h1_liS_sock} { + # Dynamic rule matching + txreq -hdr "x-dyn: 1" -hdr "x-target: be" + rxresp + expect resp.status == 200 + expect resp.http.x-be == "be" + + # Dynamic rule no match -> stay on current proxy instance + txreq -hdr "x-dyn: 1" -hdr "x-target: be_unknown" + rxresp + expect resp.status == 200 + expect resp.http.x-be == "li" +} -run