Skip to content

Commit

Permalink
Implement fail in vcl_(miss|pass|pipe|purge){}
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdphk committed Feb 6, 2017
1 parent ba54dc9 commit 6f50a00
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 7 deletions.
9 changes: 9 additions & 0 deletions bin/varnishd/cache/cache_req_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ cnt_miss(struct worker *wrk, struct req *req)
(void)HSH_DerefObjCore(wrk, &req->stale_oc, 0);
req->req_step = R_STP_FETCH;
return (REQ_FSM_MORE);
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 @@ -553,6 +556,9 @@ cnt_pass(struct worker *wrk, struct req *req)

VCL_pass_method(req->vcl, wrk, req, NULL, NULL);
switch (wrk->handling) {
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 @@ -837,6 +843,9 @@ cnt_purge(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
87 changes: 83 additions & 4 deletions bin/varnishtest/tests/v00051.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ server s1 {
varnish v1 -vcl+backend {
import debug;
sub vcl_recv {
if (req.http.foo == "pipe") {
return(pipe);
}
if (req.http.foo == "pipe") { return(pipe); }
if (req.http.foo == "pass") { return(pass); }
if (req.http.foo == "purge") { return(purge); }
if (req.http.foo == "miss") { return(hash); }
if (req.http.foo == "bar") {
return(synth(748));
}
Expand All @@ -25,12 +26,30 @@ varnish v1 -vcl+backend {
set req.http.not = "Should not happen";
}
}
sub vcl_miss {
if (req.http.foo == "miss") {
debug.fail();
set req.http.not = "Should not happen";
}
}
sub vcl_pipe {
if (req.http.foo == "pipe") {
debug.fail();
set req.http.not = "Should not happen";
}
}
sub vcl_pass {
if (req.http.foo == "pass") {
debug.fail();
set req.http.not = "Should not happen";
}
}
sub vcl_purge {
if (req.http.foo == "purge") {
debug.fail();
set req.http.not = "Should not happen";
}
}
sub vcl_synth {
if (resp.status == 748) {
debug.fail();
Expand Down Expand Up @@ -139,9 +158,69 @@ client c1 {
expect resp.reason == "VCL failed"
} -run

varnish v1 -expect sc_vcl_failure == 5

logexpect l1 -wait

#######################################################################
# Fail in vcl_pass, no handling in vcl_synth

logexpect l1 -v v1 -g raw {
expect * 1014 VCL_call "PASS"
expect 0 1014 Debug "Forced failure"
expect 0 1014 VCL_return "fail"
} -start

client c1 {
txreq -hdr "foo: pass"
rxresp
expect resp.status == 503
expect resp.reason == "VCL failed"
} -run

varnish v1 -expect sc_vcl_failure == 6

logexpect l1 -wait

#######################################################################
# Fail in vcl_purge, no handling in vcl_synth

logexpect l1 -v v1 -g raw {
expect * 1016 VCL_call "PURGE"
expect 0 1016 Debug "Forced failure"
expect 0 1016 VCL_return "fail"
} -start

client c1 {
txreq -hdr "foo: purge"
rxresp
expect resp.status == 503
expect resp.reason == "VCL failed"
} -run

varnish v1 -expect sc_vcl_failure == 7

logexpect l1 -wait

#######################################################################
# Fail in vcl_miss, no handling in vcl_synth

logexpect l1 -v v1 -g raw {
expect * 1018 VCL_call "MISS"
expect 0 1018 Debug "Forced failure"
expect 0 1018 VCL_return "fail"
} -start

client c1 {
txreq -url /x -hdr "foo: miss"
rxresp
expect resp.status == 503
expect resp.reason == "VCL failed"
} -run

delay 1

varnish v1 -expect sc_vcl_failure == 5
varnish v1 -expect sc_vcl_failure == 8

logexpect l1 -wait

6 changes: 3 additions & 3 deletions lib/libvcc/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@
),
('pass',
"C",
('synth', 'restart', 'fetch',)
('fail', 'synth', 'restart', 'fetch',)
),
('hash',
"C",
('fail', 'lookup',)
),
('purge',
"C",
('synth', 'restart',)
('fail', 'synth', 'restart',)
),
('miss',
"C",
('synth', 'restart', 'pass', 'fetch',)
('fail', 'synth', 'restart', 'pass', 'fetch',)
),
('hit',
"C",
Expand Down

0 comments on commit 6f50a00

Please sign in to comment.