Commit bfe1bcd8 authored by Nils Goroll's avatar Nils Goroll

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.
parent a4f7faec
......@@ -404,7 +404,7 @@ client c1 {
# Decode failures
server s1 -repeat 11 {
server s1 -repeat 11 -keepalive {
rxreq
txresp
} -start
......
......@@ -414,7 +414,7 @@ client c1 {
# Decode failures
server s1 -repeat 11 {
server s1 -repeat 11 -keepalive {
rxreq
txresp
} -start
......
......@@ -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
......
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
......
......@@ -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;
......
......@@ -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.
*
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment