[4.1] 93b77d9 Teach vmod-debug how to sync with varnishtest

Lasse Karstensen lkarsten at varnish-software.com
Tue Jun 14 11:19:08 CEST 2016


commit 93b77d9adaec55bc8c9edc8408f402fa2f769939
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Thu Dec 24 10:28:46 2015 +0100

    Teach vmod-debug how to sync with varnishtest

diff --git a/bin/varnishtest/tests/m00024.vtc b/bin/varnishtest/tests/m00024.vtc
new file mode 100644
index 0000000..2124589
--- /dev/null
+++ b/bin/varnishtest/tests/m00024.vtc
@@ -0,0 +1,39 @@
+varnishtest "Test debug.barrier_sync"
+
+barrier b1 sock 2
+barrier b2 sock 2
+
+server s1 {
+	rxreq
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+	import debug;
+
+	sub vcl_recv {
+		if (!debug.barrier_sync("${b1_sock}")) {
+			return (synth(400));
+		}
+	}
+
+	sub vcl_backend_response {
+		if (!debug.barrier_sync("${b2_sock}")) {
+			return (abandon);
+		}
+	}
+} -start
+
+varnish v1 -cliok "param.set debug +syncvsl"
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 200
+} -start
+
+barrier b1 sync
+delay 0.5
+barrier b2 sync
+
+client c1 -wait
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index ccf0d80..3ec9511 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -154,3 +154,7 @@ Hold a reference to the VCL when it goes cold for the given delay.
 $Function BOOL match_acl(ACL acl, IP ip)
 
 Perform an IP match against a named ACL.
+
+$Function BOOL barrier_sync(STRING)
+
+Synchronize with a varnishtest shared barrier.
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index 971e04c..40927a1 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -28,6 +28,7 @@
 
 #include "config.h"
 
+#include <errno.h>
 #include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -38,6 +39,7 @@
 #include "vrt.h"
 #include "vsa.h"
 #include "vsb.h"
+#include "vtcp.h"
 #include "vtim.h"
 #include "vcc_if.h"
 
@@ -476,3 +478,34 @@ vmod_match_acl(VRT_CTX, VCL_ACL acl, VCL_IP ip)
 
 	return (VRT_acl_match(ctx, acl, ip));
 }
+
+VCL_BOOL
+vmod_barrier_sync(VRT_CTX, VCL_STRING addr)
+{
+	const char *err;
+	char buf[32];
+	int sock;
+	ssize_t sz;
+
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	AN(addr);
+	AN(*addr);
+
+	VSLb(ctx->vsl, SLT_VCL_call, "barrier_sync(\"%s\")", addr);
+	sock = VTCP_open(addr, NULL, 0., &err);
+	if (sock < 0) {
+		VSLb(ctx->vsl, SLT_Error, "Barrier connection failed: %s", err);
+		return (0);
+	}
+
+	sz = read(sock, buf, sizeof buf);
+	if (sz == 0)
+		return (1);
+	if (sz < 0)
+		VSLb(ctx->vsl, SLT_Error,
+		    "Barrier connection failed: %s (errno=%d)",
+		    strerror(errno), errno);
+	if (sz > 0)
+		VSLb(ctx->vsl, SLT_Error, "Barrier unexpected data (%ldB)", sz);
+	return (0);
+}



More information about the varnish-commit mailing list