Commit f2caddcf authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Fix a bug in setting *.ttl variables from VCL and go over

testcases at the same time.

Spotted by:	UPLEX
parent 0c6ef776
...@@ -483,17 +483,23 @@ VRT_r_bereq_retries(const struct vrt_ctx *ctx) ...@@ -483,17 +483,23 @@ VRT_r_bereq_retries(const struct vrt_ctx *ctx)
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* NB: TTL is relative to when object was created, whereas grace and * In exp.*:
* keep are relative to ttl. * t_origin is absolute
* ttl is relative to t_origin
* grace&keep are relative to ttl
* In VCL:
* ttl is relative to now
* grace&keep are relative to ttl
*/ */
#define VRT_DO_EXP_L(which, sexp, fld) \ #define VRT_DO_EXP_L(which, sexp, fld, offset) \
\ \
void \ void \
VRT_l_##which##_##fld(const struct vrt_ctx *ctx, double a) \ VRT_l_##which##_##fld(const struct vrt_ctx *ctx, double a) \
{ \ { \
\ \
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
a += (offset); \
if (a < 0.0) \ if (a < 0.0) \
a = 0.0; \ a = 0.0; \
sexp.fld = a; \ sexp.fld = a; \
...@@ -506,23 +512,28 @@ VRT_l_##which##_##fld(const struct vrt_ctx *ctx, double a) \ ...@@ -506,23 +512,28 @@ VRT_l_##which##_##fld(const struct vrt_ctx *ctx, double a) \
double \ double \
VRT_r_##which##_##fld(const struct vrt_ctx *ctx) \ VRT_r_##which##_##fld(const struct vrt_ctx *ctx) \
{ \ { \
double d; \
\ \
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
if (sexp.fld > 0.0) \ d = sexp.fld; \
return(sexp.fld - offset); \ if (d <= 0.0) \
return(0.0); \ d = 0.0; \
d -= (offset); \
return(d); \
} }
VRT_DO_EXP_R(obj, ctx->req->objcore->exp, ttl, VRT_DO_EXP_R(obj, ctx->req->objcore->exp, ttl,
(ctx->req->t_req - ctx->req->objcore->exp.t_origin)) ctx->now - ctx->req->objcore->exp.t_origin)
VRT_DO_EXP_R(obj, ctx->req->objcore->exp, grace, 0) VRT_DO_EXP_R(obj, ctx->req->objcore->exp, grace, 0)
VRT_DO_EXP_R(obj, ctx->req->objcore->exp, keep, 0) VRT_DO_EXP_R(obj, ctx->req->objcore->exp, keep, 0)
VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, ttl) VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, ttl,
VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, ttl, 0) ctx->now - ctx->bo->fetch_objcore->exp.t_origin)
VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, grace) VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, ttl,
ctx->now - ctx->bo->fetch_objcore->exp.t_origin)
VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, grace, 0)
VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, grace, 0) VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, grace, 0)
VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, keep) VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, keep, 0)
VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, keep, 0) VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, keep, 0)
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
......
...@@ -11,6 +11,7 @@ server s1 { ...@@ -11,6 +11,7 @@ server s1 {
txresp -status "304" \ txresp -status "304" \
-hdr "Last-Modified: Thu, 26 Jun 2008 12:00:01 GMT" \ -hdr "Last-Modified: Thu, 26 Jun 2008 12:00:01 GMT" \
-hdr "Snafu: 2" \ -hdr "Snafu: 2" \
-hdr "Grifle: 3" \
-nolen -nolen
} -start } -start
...@@ -40,6 +41,7 @@ client c1 { ...@@ -40,6 +41,7 @@ client c1 {
rxresp rxresp
expect resp.bodylen == 13 expect resp.bodylen == 13
expect resp.http.foobar == foo0 expect resp.http.foobar == foo0
expect resp.http.grifle == 3
expect resp.http.snafu == 2a expect resp.http.snafu == 2a
} -run } -run
...@@ -7,6 +7,7 @@ server s1 { ...@@ -7,6 +7,7 @@ server s1 {
varnish v1 -vcl+backend { varnish v1 -vcl+backend {
sub vcl_backend_response { sub vcl_backend_response {
set beresp.http.fooA = beresp.ttl;
set beresp.ttl = 10s; set beresp.ttl = 10s;
set beresp.http.fooB = beresp.ttl; set beresp.http.fooB = beresp.ttl;
} }
...@@ -22,21 +23,22 @@ client c1 { ...@@ -22,21 +23,22 @@ client c1 {
txreq txreq
rxresp rxresp
expect resp.bodylen == 40 expect resp.bodylen == 40
expect resp.http.fooA == 19.000
expect resp.http.fooB == 10.000 expect resp.http.fooB == 10.000
delay 2 delay 2
txreq txreq
rxresp rxresp
expect resp.bodylen == 40 expect resp.bodylen == 40
# XXX: should be: < 8 expect resp.http.fooA == 19.000
expect resp.http.fooB == 10.000 expect resp.http.fooB == 10.000
expect resp.http.foo != 10.000 expect resp.http.foo <= 8.000
expect resp.http.foo != 9.000
delay 2 delay 2
txreq txreq
rxresp rxresp
expect resp.bodylen == 40 expect resp.bodylen == 40
expect resp.http.fooA == 19.000
expect resp.http.fooB == 10.000 expect resp.http.fooB == 10.000
expect resp.http.foo <= 5.000 expect resp.http.foo <= 6.000
} -run } -run
...@@ -21,7 +21,7 @@ client c1 { ...@@ -21,7 +21,7 @@ client c1 {
txreq txreq
rxresp rxresp
expect resp.bodylen == 40 expect resp.bodylen == 40
expect resp.http.x-ttl == 23.000 expect resp.http.x-ttl == 19.000
expect resp.http.Age == 4 expect resp.http.Age == 4
...@@ -29,13 +29,13 @@ client c1 { ...@@ -29,13 +29,13 @@ client c1 {
txreq txreq
rxresp rxresp
expect resp.bodylen == 40 expect resp.bodylen == 40
expect resp.http.x-ttl == 23.000 expect resp.http.x-ttl == 19.000
expect resp.http.x-remaining-ttl ~ ^17\.0|^16\.[89] expect resp.http.x-remaining-ttl <= 17.000
delay 2 delay 2
txreq txreq
rxresp rxresp
expect resp.bodylen == 40 expect resp.bodylen == 40
expect resp.http.x-ttl == 23.000 expect resp.http.x-ttl == 19.000
expect resp.http.x-remaining-ttl ~ ^15\.0|^14\.[89] expect resp.http.x-remaining-ttl <= 15.000
} -run } -run
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