varnishtest "Backend close retry"

server s1 -repeat 1 {
	rxreq
	txresp -noserver -nodate -bodylen 5

	rxreq
	accept

	rxreq
	txresp -noserver -nodate -bodylen 6

} -start

varnish v1 -vcl+backend {
	sub vcl_recv {
		return(pass);
	}
} -start

logexpect l1 -v v1 -q "vxid == 1004" {
	expect * 1004 VCL_return      {^fetch}
	expect 0 1004 Timestamp       {^Fetch:}
	expect 0 1004 Timestamp       {^Connected:}
	expect 0 1004 BackendOpen     {^\d+ s1}
	expect 0 1004 Timestamp       {^Bereq:}

	# purpose of this vtc: test the internal retry when the
	# backend goes away on a keepalive TCP connection:
	expect 0 1004 FetchError      {^HTC eof .Unexpected end of input.}
	expect 0 1004 BackendClose    {^\d+ s1}
	expect 0 1004 Timestamp       {^Connected:}
	expect 0 1004 BackendOpen     {^\d+ s1}

	expect 0 1004 Timestamp       {^Bereq:}
	expect 0 1004 BerespProtocol  {^HTTP/1.1}
	expect 0 1004 BerespStatus    {^200}
	expect 0 1004 BerespReason    {^OK}
	expect 0 1004 BerespHeader    {^Content-Length: 6}
	expect 0 1004 Timestamp       {^Beresp:}
} -start

client c1 {
	txreq
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 5

	txreq
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 6
} -run

varnish v1 -expect backend_retry == 1
logexpect l1 -wait
