varnishtest "Check that the first_byte_timeout works"

# From VCL

server s1 {
	rxreq
	delay 1
	txresp
} -start

varnish v1 -vcl+backend {
	sub vcl_recv {
		return (pass);
	}
	sub vcl_backend_fetch {
		set bereq.first_byte_timeout = 0.5s;
	}
} -start

client c1 {
	txreq
	rxresp
	expect resp.status == 503
} -run

server s1 {
	rxreq
	delay 0.2
	txresp
} -start

client c2 {
	txreq
	rxresp
	expect resp.status == 200
} -run

# From CLI

varnish v1 -vcl+backend {
	sub vcl_recv {
		return (pass);
	}
}
varnish v1 -cliok "param.set first_byte_timeout 0.5"

server s1 {
	rxreq
	delay 1
	txresp
} -start

client c1 -run

server s1 {
	rxreq
	delay 0.2
	txresp
} -start

client c2 -run

# From backend definition

server s1 {
	rxreq
	delay 1
	txresp
} -start

varnish v1 -vcl {
	backend b1 {
		.host = "${s1_addr}";
		.port = "${s1_port}";
		.first_byte_timeout = 0.5s;
	}
}

client c1 -run

server s1 {
	rxreq
	delay 0.2
	txresp
} -start

client c2 -run

varnish v1 -expect fetch_failed == 3
