Skip to content

Commit

Permalink
Implement fail in vcl_hit{} and vcl_deliver{}
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdphk committed Feb 6, 2017
1 parent 1567375 commit b881699
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
6 changes: 6 additions & 0 deletions bin/varnishd/cache/cache_req_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
65 changes: 61 additions & 4 deletions bin/varnishtest/tests/v00051.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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"
Expand All @@ -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

4 changes: 2 additions & 2 deletions lib/libvcc/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@
),
('hit',
"C",
('synth', 'restart', 'pass', 'miss', 'deliver',)
('fail', 'synth', 'restart', 'pass', 'miss', 'deliver',)
),
('deliver',
"C",
('synth', 'restart', 'deliver',)
('fail', 'synth', 'restart', 'deliver',)
),
('synth',
"C",
Expand Down

0 comments on commit b881699

Please sign in to comment.