varnishtest "Test v4 grace"

barrier b1 cond 2

server s1 {
	rxreq
	txresp -hdr "Last-Modified: Mon, 09 Feb 2015 09:32:47 GMT" -bodylen 3
	rxreq
	txresp -bodylen 6
	barrier b1 sync
} -start

varnish v1 -vcl+backend {
	sub vcl_backend_response {
		set beresp.ttl = 0.5s;
		set beresp.grace = 10s;
	}
} -start


client c1 {
	txreq
	rxresp
	expect resp.bodylen == 3

	delay 1
} -run

varnish v1 -expect n_object == 1

client c1 {
	# We still get old object
	txreq
	rxresp
	expect resp.bodylen == 3

	# But bg fetch was kicked off
	barrier b1 sync
	delay .2

	# And now we get the new object
	txreq
	rxresp
	expect resp.bodylen == 6
} -run

# and the old one has got superseded
varnish v1 -expect n_object == 1
