vtest "1399 race issue with bg-fetches"

barrier b1 cond 2

server s1 {
	rxreq
	expect req.http.Is-bg == "false"
	txresp -bodylen 1

	barrier b1 sync

	# Delay here, to stall the bgfetch for a while, to give the req time to finish
	# delivery and cleanup up struct req
	delay 2

	# Shut the connection to force the bgfetch to retry
	close
	accept

	# And see if it has all its marbles still...
	rxreq
	expect req.url == "/"
	expect req.http.Is-bg == "true"
	txresp -bodylen 2

} -start

vinyl v1 -vcl+backend {
	sub vcl_backend_fetch {
		set bereq.http.Is-bg = bereq.is_bgfetch;
	}
	sub vcl_backend_response {
		set beresp.do_stream = false;
		set beresp.ttl = 2s;
		set beresp.grace = 1800s;
	}
} -start

client c1 {
	txreq
	rxresp
	expect resp.http.content-length == 1

} -run

# 3 is longer than the ttl, in order to kick off the bgfetch
delay 3

client c1 {
	txreq
	rxresp
	expect resp.http.content-length == 1
	barrier b1 sync
} -run

# Wait for the server to not explode
server s1 -wait
