[6.0] 5e9e1cdcb varnishtest: add -keepalive to repeat on a single connection

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Oct 31 13:08:11 UTC 2018


commit 5e9e1cdcb45a10b04e1070edd47fc86d00a94636
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Thu Aug 30 17:44:07 2018 +0200

    varnishtest: add -keepalive to repeat on a single connection
    
    For tests which do not require new connections for repetitions (for
    example because of possible error conditions), this reduces run time
    and the number of required ephemeral ports.
    
    The latter is a real issue when running many vtcs in parallel which
    each run many repetitions of the same test (for example to check for
    possible race conditions). When ephemeral ports are exhausted,
    seemingly unrelated issues like the following can be observed:
    
    ---- c1010 14.0 Failed to open 127.0.0.1 59763: (null)
    
    **** v1    1.8 vsl|          0 CLI             - Wr 300 65 Listen failed
    on socket '127.0.0.1:33328': Address already in use
    **** v1    1.8 vsl|          0 CLI             - EOF on CLI connection,
    worker stops
    
    An argument could be made that UDS does not suffer from the port
    exhaustion issue and thus such tests could be migrated to UDS. Yet
    also for this case the run time point remains, plus deliberately
    testing many iterations on a single connection could have its own
    merits.

diff --git a/bin/varnishtest/tests/m00041.vtc b/bin/varnishtest/tests/m00041.vtc
index 4c543d845..aeda981f9 100644
--- a/bin/varnishtest/tests/m00041.vtc
+++ b/bin/varnishtest/tests/m00041.vtc
@@ -404,7 +404,7 @@ client c1 {
 
 # Decode failures
 
-server s1 -repeat 11 {
+server s1 -repeat 11 -keepalive {
 	rxreq
 	txresp
 } -start
diff --git a/bin/varnishtest/tests/m00042.vtc b/bin/varnishtest/tests/m00042.vtc
index aaac4b917..6e6004f63 100644
--- a/bin/varnishtest/tests/m00042.vtc
+++ b/bin/varnishtest/tests/m00042.vtc
@@ -414,7 +414,7 @@ client c1 {
 
 # Decode failures
 
-server s1 -repeat 11 {
+server s1 -repeat 11 -keepalive {
 	rxreq
 	txresp
 } -start
diff --git a/bin/varnishtest/tests/r01834.vtc b/bin/varnishtest/tests/r01834.vtc
index 827105b8b..33437a9b2 100644
--- a/bin/varnishtest/tests/r01834.vtc
+++ b/bin/varnishtest/tests/r01834.vtc
@@ -4,6 +4,7 @@ varnishtest "#1834 - Buffer overflow in backend workspace"
 # workspace left. If failing it would be because we tripped the canary
 # at the end of the workspace.
 
+
 server s1 -repeat 64 {
 	rxreq
 	txresp
diff --git a/bin/varnishtest/tests/r02372.vtc b/bin/varnishtest/tests/r02372.vtc
index c32d17b96..a01401f16 100644
--- a/bin/varnishtest/tests/r02372.vtc
+++ b/bin/varnishtest/tests/r02372.vtc
@@ -1,6 +1,6 @@
 varnishtest "Count purges when there are many variants"
 
-server s1 -repeat 72 {
+server s1 -repeat 72 -keepalive {
 	rxreq
 	txresp -hdr "Vary: foo"
 } -start
@@ -16,7 +16,7 @@ varnish v1 -arg "-p workspace_thread=512" -vcl+backend {
 	}
 } -start
 
-client c1 -repeat 72 {
+client c1 -repeat 72 -keepalive {
 	txreq
 	rxresp
 } -run
diff --git a/bin/varnishtest/vtc_client.c b/bin/varnishtest/vtc_client.c
index d2f72b955..5c714de0b 100644
--- a/bin/varnishtest/vtc_client.c
+++ b/bin/varnishtest/vtc_client.c
@@ -60,6 +60,7 @@ struct client {
 	int			proxy_version;
 
 	unsigned		repeat;
+	unsigned		keepalive;
 
 	unsigned		running;
 	pthread_t		tp;
@@ -215,7 +216,8 @@ client_thread(void *priv)
 	if (c->repeat == 0)
 		c->repeat = 1;
 	if (c->repeat != 1)
-		vtc_log(vl, 2, "Started (%u iterations)", c->repeat);
+		vtc_log(vl, 2, "Started (%u iterations%s)", c->repeat,
+			c->keepalive ? " using keepalive" : "");
 	for (u = 0; u < c->repeat; u++) {
 		char *addr = VSB_data(vsb);
 
@@ -231,7 +233,11 @@ client_thread(void *priv)
 		(void)VTCP_blocking(fd);
 		if (c->proxy_spec != NULL)
 			client_proxy(vl, fd, c->proxy_version, c->proxy_spec);
-		fd = http_process(vl, c->spec, fd, NULL, addr);
+		if (! c->keepalive)
+			fd = http_process(vl, c->spec, fd, NULL, addr);
+		else
+			while (fd >= 0 && u++ < c->repeat)
+				fd = http_process(vl, c->spec, fd, NULL, addr);
 		vtc_log(vl, 3, "closing fd %d", fd);
 		VTCP_close(&fd);
 	}
@@ -393,6 +399,10 @@ cmd_client(CMD_ARGS)
 			av++;
 			continue;
 		}
+		if (!strcmp(*av, "-keepalive")) {
+			c->keepalive = 1;
+			continue;
+		}
 		if (!strcmp(*av, "-start")) {
 			client_start(c);
 			continue;
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 741c5f12a..d89a91a5a 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -95,6 +95,10 @@ extern const struct cmds http_cmds[];
  * \-repeat NUMBER
  *        Instead of processing the specification only once, do it NUMBER times.
  *
+ * \-keepalive
+ *        For repeat, do not open new connections but rather run all
+ *        iterations in the same connection
+ *
  * \-break (server only)
  *        Stop the server.
  *
diff --git a/bin/varnishtest/vtc_server.c b/bin/varnishtest/vtc_server.c
index 4876352f2..d156185d9 100644
--- a/bin/varnishtest/vtc_server.c
+++ b/bin/varnishtest/vtc_server.c
@@ -52,6 +52,7 @@ struct server {
 	char			run;
 
 	unsigned		repeat;
+	unsigned		keepalive;
 	char			*spec;
 
 	int			depth;
@@ -234,10 +235,9 @@ server_thread(void *priv)
 	vl = vtc_logopen(s->name);
 	pthread_cleanup_push(vtc_logclose, vl);
 
-	vtc_log(vl, 2, "Started on %s", s->listen);
+	vtc_log(vl, 2, "Started on %s (%u iterations%s)", s->listen,
+		s->repeat, s->keepalive ? " using keepalive" : "");
 	for (i = 0; i < s->repeat; i++) {
-		if (s->repeat > 1)
-			vtc_log(vl, 3, "Iteration %d", i);
 		addr = (void*)&addr_s;
 		l = sizeof addr_s;
 		fd = accept(s->sock, addr, &l);
@@ -248,7 +248,12 @@ server_thread(void *priv)
 			vtc_log(vl, 3, "accepted fd %d %s %s", fd, abuf, pbuf);
 		} else
 			vtc_log(vl, 3, "accepted fd %d 0.0.0.0 0", fd);
-		fd = http_process(vl, s->spec, fd, &s->sock, s->listen);
+		if (! s->keepalive)
+			fd = http_process(vl, s->spec, fd, &s->sock, s->listen);
+		else
+			while (fd >= 0 && i++ < s->repeat)
+				fd = http_process(vl, s->spec, fd,
+				    &s->sock, s->listen);
 		vtc_log(vl, 3, "shutting fd %d", fd);
 		j = shutdown(fd, SHUT_WR);
 		if (!VTCP_Check(j))
@@ -526,6 +531,10 @@ cmd_server(CMD_ARGS)
 			av++;
 			continue;
 		}
+		if (!strcmp(*av, "-keepalive")) {
+			s->keepalive = 1;
+			continue;
+		}
 		if (!strcmp(*av, "-listen")) {
 			if (s->sock >= 0)
 				VTCP_close(&s->sock);


More information about the varnish-commit mailing list