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.
This commit is contained in:
Amaury Denoyelle 2026-01-09 11:17:38 +01:00
parent 12975c5c37
commit 2d26d353ce

View File

@ -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