[master] 811c0c5 Add test for support of PRIV_TASK in CLI induced VCL events.
Nils Goroll
nils.goroll at uplex.de
Mon Sep 12 11:14:14 CEST 2016
commit 811c0c5493831b24ed971fec6a15180774922b41
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Mon Sep 12 11:09:51 2016 +0200
Add test for support of PRIV_TASK in CLI induced VCL events.
Part of #2061
diff --git a/bin/varnishtest/tests/v00041.vtc b/bin/varnishtest/tests/v00041.vtc
index b5c053c..b111796 100644
--- a/bin/varnishtest/tests/v00041.vtc
+++ b/bin/varnishtest/tests/v00041.vtc
@@ -11,13 +11,21 @@ varnish v1 -vcl+backend {
import debug;
import std;
+ sub vcl_init {
+ debug.test_priv_task("something");
+ debug.test_priv_task("to remember");
+ std.log(debug.test_priv_task());
+ }
+
sub vcl_recv {
- set req.http.x0 = debug.test_priv_task(req.url);
+ debug.test_priv_task(req.url);
+ set req.http.x0 = debug.test_priv_task();
+ debug.test_priv_task("bazz");
}
sub vcl_deliver {
set resp.http.x0 = req.http.x0;
- set resp.http.x1 = debug.test_priv_task("");
+ set resp.http.x1 = debug.test_priv_task();
}
sub vcl_backend_fetch {
@@ -32,19 +40,37 @@ varnish v1 -vcl+backend {
}
} -start
+logexpect l1 -v v1 -g raw -d 1 {
+ expect 0 0 CLI {^Rd vcl.load}
+ expect 0 = VCL_Log {^something to remember}
+
+ expect * 1002 Begin fetch$
+ expect * = VCL_call ^BACKEND_FETCH
+ expect 0 = VCL_Log ^foo
+ expect 0 = BereqHeader {^bx0: /foobar}
+ expect 0 = VCL_Log ^bar
+
+ expect * 1004 Begin fetch$
+ expect * = VCL_call ^BACKEND_FETCH
+ expect 0 = VCL_Log ^foo
+ expect 0 = BereqHeader {^bx0: /snafu}
+ expect 0 = VCL_Log ^bar
+} -start
client c1 {
txreq -url /foobar
rxresp
expect resp.http.x0 == /foobar
- expect resp.http.x1 == /foobar
+ expect resp.http.x1 == "/foobar bazz"
expect resp.http.bx0 == /foobar
expect resp.http.bx1 == /foobar
txreq -url /snafu
rxresp
expect resp.http.x0 == /snafu
- expect resp.http.x1 == /snafu
+ expect resp.http.x1 == "/snafu bazz"
expect resp.http.bx0 == /snafu
expect resp.http.bx1 == /snafu
} -run
+
+logexpect l1 -wait
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index cbe9de8..f20c127 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -51,7 +51,7 @@ $Function VOID test_priv_vcl(PRIV_VCL)
Test function for VCL private pointers
-$Function STRING test_priv_task(PRIV_TASK, STRING)
+$Function STRING test_priv_task(PRIV_TASK, STRING s="")
Test function for TASK private pointers
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index dc9e347..3322da7 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -101,9 +101,19 @@ vmod_test_priv_task(VRT_CTX, struct vmod_priv *priv, VCL_STRING s)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
- if (priv->priv == NULL) {
+ if (s == NULL || *s == '\0') {
+ return priv->priv;
+ } else if (priv->priv == NULL) {
priv->priv = strdup(s);
priv->free = free;
+ } else {
+ char *n = realloc(priv->priv,
+ strlen(priv->priv) + strlen(s) + 2);
+ if (n == NULL)
+ return NULL;
+ strcat(n, " ");
+ strcat(n, s);
+ priv->priv = n;
}
return (priv->priv);
}
More information about the varnish-commit
mailing list