vtest "Test parking second request on backend delay, then pass"

barrier b1 cond 2

server s1 {
	rxreq
	expect req.url == "/foo"
	barrier b1 sync
	send "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\n"
	send "line1\n"
	send "line2\n"

	rxreq
	expect req.url == "/foo"
	txresp -body "foobar"
} -start

vinyl v1 -vcl+backend {
	sub vcl_miss {
		set req.http.hitmiss = req.is_hitmiss;
	}
	sub vcl_deliver {
		set resp.http.hitmiss = req.http.hitmiss;
	}
	sub vcl_backend_response {
		set beresp.do_stream = false;
		set beresp.uncacheable = true;
	}
} -start

client c1 {
	txreq -url "/foo"
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 12
	expect resp.http.X-Vinyl == "1001"
	expect resp.http.hitmiss == "false"
} -start

barrier b1 sync
delay .2

client c2 {
	txreq -url "/foo"
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 6
	expect resp.http.X-Vinyl == "1004"
	expect resp.http.hitmiss == "true"
} -run

client c1 -wait

vinyl v1 -expect cache_hitpass == 0
vinyl v1 -expect cache_hitmiss == 1
vinyl v1 -expect cache_miss == 2
