vtest "purge stale on refresh with and without IMS"

server s1 {
	rxreq
	expect req.url == /no-ims
	txresp -hdr "foo: bar" -body "1"
	rxreq
	expect req.url == /ims
	txresp -hdr "foo: bar" -hdr {ETag: "asdf"} -body "12"

	rxreq
	txresp -hdr "foo: baz" -body "123"
	rxreq
	expect req.http.if-none-match == {"asdf"}
	txresp -status 304 -nolen -hdr "foo: bazf"
} -start

vinyl v1 -vcl+backend {
	sub vcl_backend_response {
		set beresp.ttl = 0.1s;
		set beresp.grace = 0s;
		set beresp.keep = 60s;
	}
} -start

client c1 {
	txreq -url /no-ims
	rxresp
	expect resp.bodylen == 1
	expect resp.http.foo == "bar"

	txreq -url /ims
	rxresp
	expect resp.bodylen == 2
	expect resp.http.foo == "bar"
} -run

# Wait for ttl to expire on both objects
delay 0.2
vinyl v1 -expect n_object == 2

client c1 {
	txreq -url /no-ims
	rxresp
	expect resp.bodylen == 3
	expect resp.http.foo == "baz"

	txreq -url /ims
	rxresp
	expect resp.bodylen == 2
	expect resp.http.foo == "bazf"
} -run

# Make sure expiry is done
delay 1

# Only one of each of /no-ims and /ims should be left
vinyl v1 -expect n_object == 2
