[master] b881699 Implement fail in vcl_hit{} and vcl_deliver{}
Poul-Henning Kamp
phk at FreeBSD.org
Mon Feb 6 23:29:05 CET 2017
commit b8816994cfab58261d8000ea8e6941cb5de640fa
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Feb 6 22:27:43 2017 +0000
Implement fail in vcl_hit{} and vcl_deliver{}
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 5463e56..0f6f88e 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -117,6 +117,9 @@ cnt_deliver(struct worker *wrk, struct req *req)
case VCL_RET_RESTART:
req->req_step = R_STP_RESTART;
break;
+ case VCL_RET_FAIL:
+ req->req_step = R_STP_VCLFAIL;
+ break;
case VCL_RET_SYNTH:
req->req_step = R_STP_SYNTH;
break;
@@ -474,6 +477,9 @@ cnt_lookup(struct worker *wrk, struct req *req)
case VCL_RET_RESTART:
req->req_step = R_STP_RESTART;
break;
+ case VCL_RET_FAIL:
+ req->req_step = R_STP_VCLFAIL;
+ break;
case VCL_RET_SYNTH:
req->req_step = R_STP_SYNTH;
break;
diff --git a/bin/varnishtest/tests/v00051.vtc b/bin/varnishtest/tests/v00051.vtc
index 4e486dd..8a36d61 100644
--- a/bin/varnishtest/tests/v00051.vtc
+++ b/bin/varnishtest/tests/v00051.vtc
@@ -232,9 +232,6 @@ logexpect l1 -wait
varnish v1 -vcl+backend {
import debug;
- sub vcl_recv {
- if (req.http.foo == "miss") { return(hash); }
- }
sub vcl_miss {
if (req.http.foo == "miss") {
debug.fail();
@@ -250,7 +247,7 @@ logexpect l1 -v v1 -g raw {
} -start
client c1 {
- txreq -url /x -hdr "foo: miss"
+ txreq -url /miss -hdr "foo: miss"
rxresp
expect resp.status == 503
expect resp.reason == "VCL failed"
@@ -260,3 +257,63 @@ varnish v1 -expect sc_vcl_failure == 8
logexpect l1 -wait
+#######################################################################
+# Fail in vcl_hit
+
+varnish v1 -vcl+backend {
+ import debug;
+ sub vcl_hit {
+ if (req.http.foo == "hit") {
+ debug.fail();
+ set req.http.not = "Should not happen";
+ }
+ }
+}
+
+logexpect l1 -v v1 -g raw {
+ expect * 1020 VCL_call "HIT"
+ expect 0 1020 Debug "Forced failure"
+ expect 0 1020 VCL_return "fail"
+} -start
+
+client c1 {
+ txreq -url /hit -hdr "foo: hit"
+ rxresp
+ expect resp.status == 503
+ expect resp.reason == "VCL failed"
+} -run
+
+varnish v1 -expect sc_vcl_failure == 9
+
+logexpect l1 -wait
+
+#######################################################################
+# Fail in vcl_deliver
+
+varnish v1 -vcl+backend {
+ import debug;
+ sub vcl_deliver {
+ if (req.http.foo == "deliver") {
+ debug.fail();
+ set req.http.not = "Should not happen";
+ }
+ }
+}
+
+logexpect l1 -v v1 -g raw {
+ expect * 1022 VCL_call "DELIVER"
+ expect 0 1022 Debug "Forced failure"
+ expect 0 1022 VCL_return "fail"
+} -start
+
+client c1 {
+ txreq -url /hit -hdr "foo: deliver"
+ rxresp
+ expect resp.status == 503
+ expect resp.reason == "VCL failed"
+} -run
+
+varnish v1 -expect sc_vcl_failure == 10
+
+logexpect l1 -wait
+
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 285f126..7dcafc3 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -114,11 +114,11 @@ returns = (
),
('hit',
"C",
- ('synth', 'restart', 'pass', 'miss', 'deliver',)
+ ('fail', 'synth', 'restart', 'pass', 'miss', 'deliver',)
),
('deliver',
"C",
- ('synth', 'restart', 'deliver',)
+ ('fail', 'synth', 'restart', 'deliver',)
),
('synth',
"C",
More information about the varnish-commit
mailing list