Commit f445be5b authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

Teach vmod-debug how to sync with varnishtest

parent db395f8d
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
......@@ -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.
......@@ -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"
......@@ -478,3 +480,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);
}
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