[4.1] 1a3b0ff This seems to get test-termination to stabilize, including the new improved probability of getting the VSL out.
Lasse Karstensen
lkarsten at varnish-software.com
Thu Jan 14 15:15:11 CET 2016
commit 1a3b0ff51af1a258e7cbb77cd34341f9ccbedb1e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Jan 6 16:25:13 2016 +0000
This seems to get test-termination to stabilize, including the
new improved probability of getting the VSL out.
diff --git a/bin/varnishtest/tests/b00044.vtc b/bin/varnishtest/tests/b00044.vtc
index 5d02319..463e383 100644
--- a/bin/varnishtest/tests/b00044.vtc
+++ b/bin/varnishtest/tests/b00044.vtc
@@ -15,3 +15,5 @@ client c1 {
server s1 -wait
shell "kill -15 ${v1_pid}"
+
+varnish v1 -cleanup
diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index 3c6c884..33b56e1 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -684,7 +684,7 @@ exec_file(const char *fn, const char *script, const char *tmpdir,
vtc_stop = 1;
vtc_log(vltop, 1, "RESETTING after %s", fn);
reset_cmds(cmds);
- vtc_error = old_err;
+ vtc_error |= old_err;
if (vtc_error)
vtc_log(vltop, 1, "TEST %s FAILED", fn);
diff --git a/bin/varnishtest/vtc_log.c b/bin/varnishtest/vtc_log.c
index 4a73ebd..30ae6b8 100644
--- a/bin/varnishtest/vtc_log.c
+++ b/bin/varnishtest/vtc_log.c
@@ -112,8 +112,6 @@ vtc_log_emit(const struct vtclog *vl, int lvl)
if (lvl < 0)
lvl = 0;
- if (vtc_stop && lvl == 0)
- return;
l = VSB_len(vl->vsb);
AZ(pthread_mutex_lock(&vtclog_mtx));
assert(vtclog_left > l);
diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index 77d8715..91c4072 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -78,7 +78,7 @@ struct varnish {
struct VSM_data *vd; /* vsc use */
unsigned vsl_tag_count[256];
-
+
volatile int vsl_idle;
};
@@ -209,6 +209,7 @@ varnishlog_thread(void *priv)
opt = 0;
while (v->pid) {
if (c == NULL) {
+ v->vsl_idle++;
VTIM_sleep(0.1);
if (VSM_Open(vsm)) {
VSM_ResetError(vsm);
@@ -257,6 +258,8 @@ varnishlog_thread(void *priv)
type, (int)len, data);
}
+ v->vsl_idle = 100;
+
if (c)
VSL_DeleteCursor(c);
VSL_Delete(vsl);
@@ -343,28 +346,29 @@ varnish_thread(void *priv)
{
struct varnish *v;
char buf[65536];
- struct pollfd *fds, fd;
+ struct pollfd fds[1];
int i;
CAST_OBJ_NOTNULL(v, priv, VARNISH_MAGIC);
(void)VTCP_nonblocking(v->fds[0]);
while (1) {
- fds = &fd;
- memset(fds, 0, sizeof *fds);
+ memset(fds, 0, sizeof fds);
fds->fd = v->fds[0];
fds->events = POLLIN;
i = poll(fds, 1, 1000);
if (i == 0)
continue;
+ if (fds->revents & POLLIN) {
+ i = read(v->fds[0], buf, sizeof buf - 1);
+ if (i > 0) {
+ buf[i] = '\0';
+ vtc_dump(v->vl, 3, "debug", buf, -2);
+ }
+ }
if (fds->revents & (POLLERR|POLLHUP)) {
vtc_log(v->vl, 4, "STDOUT poll 0x%x", fds->revents);
break;
}
- i = read(v->fds[0], buf, sizeof buf - 1);
- if (i <= 0)
- break;
- buf[i] = '\0';
- vtc_dump(v->vl, 3, "debug", buf, -2);
}
return (NULL);
}
@@ -589,41 +593,42 @@ varnish_stop(struct varnish *v)
}
/**********************************************************************
- * Wait for a Varnish
+ * Cleanup
*/
static void
-varnish_wait(struct varnish *v)
+varnish_cleanup(struct varnish *v)
{
void *p;
int status, r;
struct rusage ru;
- char *resp;
- if (v->cli_fd < 0)
- return;
- varnish_ask_cli(v, "backend.list", &resp);
+ /* Give the VSL log time to finish */
while (v->vsl_idle < 10)
(void)usleep(200000);
- if (vtc_error)
- (void)sleep(1); /* give panic messages a chance */
- varnish_stop(v);
- vtc_log(v->vl, 2, "Wait");
+
+ /* Close the CLI connection */
AZ(close(v->cli_fd));
v->cli_fd = -1;
- (void)close(v->fds[1]); /* May already have been closed */
+ /* Close the STDIN connection. */
+ AZ(close(v->fds[1]));
+ /* Wait until STDOUT+STDERR closes */
AZ(pthread_join(v->tp, &p));
AZ(close(v->fds[0]));
+
r = wait4(v->pid, &status, 0, &ru);
v->pid = 0;
vtc_log(v->vl, 2, "R %d Status: %04x (u %.6f s %.6f)", r, status,
ru.ru_utime.tv_sec + 1e-6 * ru.ru_utime.tv_usec,
ru.ru_stime.tv_sec + 1e-6 * ru.ru_stime.tv_usec
);
+
+ /* Pick up the VSL thread */
AZ(pthread_join(v->tp_vsl, &p));
- if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
+
+ if (WIFEXITED(status) && (WEXITSTATUS(status) == 0))
return;
#ifdef WCOREDUMP
vtc_log(v->vl, 0, "Bad exit code: %04x sig %x exit %x core %x",
@@ -636,6 +641,30 @@ varnish_wait(struct varnish *v)
}
/**********************************************************************
+ * Wait for a Varnish
+ */
+
+static void
+varnish_wait(struct varnish *v)
+{
+ char *resp;
+
+ if (v->cli_fd < 0)
+ return;
+
+ vtc_log(v->vl, 2, "Wait");
+
+ /* Do a backend.list to log if child is still running */
+ varnish_ask_cli(v, "backend.list", &resp);
+
+ /* Then stop it */
+ varnish_stop(v);
+
+ varnish_cleanup(v);
+}
+
+
+/**********************************************************************
* Ask a CLI question
*/
@@ -930,6 +959,11 @@ cmd_varnish(CMD_ARGS)
av += 2;
continue;
}
+ if (!strcmp(*av, "-cleanup")) {
+ AZ(av[1]);
+ varnish_cleanup(v);
+ continue;
+ }
if (!strcmp(*av, "-cliok")) {
AN(av[1]);
varnish_cli(v, av[1], (unsigned)CLIS_OK);
More information about the varnish-commit
mailing list