[master] 884ef9da0 Explicitly test connection pooling works properly

Nils Goroll nils.goroll at uplex.de
Mon Feb 20 15:38:06 UTC 2023


commit 884ef9da03de1d586ec580dbf60e9b51be63eb2a
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Dec 6 17:05:35 2021 +0100

    Explicitly test connection pooling works properly
    
    Connect to s1 and s2 via v2.
    
    Note on the v2 VCL: We use this varnish instance as a PROXY protocol
    aware forwarder, which takes the address to connect to from the
    incoming PROXY header (to mimic haproxy instead of requiring it).
    
    Previously, we used debug.dyn(), but that does not work with two
    different backends because it does not create different backend
    instances, so connection pooling fails on this level, unrelated to the
    actual test subject.
    
    We avoid this issue by an explicit VCL implementation.

diff --git a/bin/varnishtest/tests/c00042.vtc b/bin/varnishtest/tests/c00042.vtc
index 894fc5c07..698599d99 100644
--- a/bin/varnishtest/tests/c00042.vtc
+++ b/bin/varnishtest/tests/c00042.vtc
@@ -3,30 +3,38 @@ varnishtest "Test vcl defined via backends"
 server s1 {
 	loop 5 {
 		rxreq
-		txresp
+		txresp -hdr "Server: s1"
 	}
 } -start
 
+server s2 {
+	rxreq
+	txresp -hdr "Server: s2"
+} -start
+
 # the use case for via-proxy is to have a(n ha)proxy make a(n ssl)
 # connection on our behalf. For the purpose of testing, we use another
 # varnish in place - but we are behaving realistically in that we do
 # not use any prior information for the actual backend connection -
 # just the information from the proxy protocol
 
-varnish v2 -proto PROXY -vcl {
-	import debug;
+varnish v2 -proto PROXY -vcl+backend {
 	import std;
 	import proxy;
 
-	backend dummy { .host = "${bad_backend}"; }
-
-	sub vcl_init {
-		new s1 = debug.dyn("0.0.0.0", "0");
-	}
-
 	sub vcl_recv {
-		s1.refresh(server.ip, std.port(server.ip));
-		set req.backend_hint = s1.backend();
+		if (server.ip == "${s1_addr}" &&
+		    std.port(server.ip) == ${s1_port}) {
+			set req.backend_hint = s1;
+		} else
+		if (server.ip == "${s2_addr}" &&
+		    std.port(server.ip) == ${s2_port}) {
+			set req.backend_hint = s2;
+		}
+		else {
+		    return (synth(404, "unknown backend"));
+		}
+		std.log("PROXY " + req.url + " -> " + req.backend_hint);
 		return (pass);
 	}
 
@@ -35,24 +43,42 @@ varnish v2 -proto PROXY -vcl {
 	}
 } -start
 
+varnish v2 -cliok "param.set debug +syncvsl"
+
 varnish v1 -vcl {
 	backend v2 { .host = "${v2_addr}"; .port = "${v2_port}"; }
 	backend s1 { .via = v2; .host = "${s1_addr}"; .port = "${s1_port}"; }
+	backend s2 { .via = v2; .host = "${s2_addr}"; .port = "${s2_port}"; }
 
 	sub vcl_recv {
-		set req.backend_hint = s1;
+		if (req.url ~ "^/s1/") {
+			set req.backend_hint = s1;
+		} else if (req.url ~ "^/s2/") {
+			set req.backend_hint = s2;
+		} else {
+			return (synth(400));
+		}
 	}
 } -start
 
 client c1 {
-	txreq -url /1
+	txreq -url /s1/1
+	rxresp
+	expect resp.status == 200
+	expect resp.http.Authority == "127.0.0.1"
+	expect resp.http.Server == "s1"
+
+	txreq -url /s2/1
 	rxresp
 	expect resp.status == 200
 	expect resp.http.Authority == "127.0.0.1"
-	txreq -url /2
+	expect resp.http.Server == "s2"
+
+	txreq -url /s1/2
 	rxresp
 	expect resp.status == 200
 	expect resp.http.Authority == "127.0.0.1"
+	expect resp.http.Server == "s1"
 } -run
 
 varnish v1 -vcl {
@@ -71,7 +97,7 @@ varnish v1 -vcl {
 }
 
 client c1 {
-	txreq -url /3
+	txreq -url /s1/3
 	rxresp
 	expect resp.status == 200
 	expect resp.http.Authority == "authority.com"
@@ -93,7 +119,7 @@ varnish v1 -vcl {
 }
 
 client c1 {
-	txreq -url /4
+	txreq -url /s1/4
 	rxresp
 	expect resp.status == 200
 	expect resp.http.Authority == "host.com"
@@ -116,7 +142,7 @@ varnish v1 -vcl {
 }
 
 client c1 {
-	txreq -url /5
+	txreq -url /s1/5
 	rxresp
 	expect resp.status == 200
 	# vmod_proxy returns the empty string if the TLV is absent.


More information about the varnish-commit mailing list