vtest "Check that the first_byte_timeout works"

# From VCL

server s1 {
	rxreq
	delay 1
	txresp
} -start

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

logexpect l1 -v v1 {
	expect * 1002   FetchError      "first byte timeout"
} -start

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

logexpect l1 -wait

server s1 {
	rxreq
	delay 0.2
	txresp
} -start

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

# From CLI

vinyl v1 -vcl+backend {
	sub vcl_recv {
		return (pass);
	}
}
vinyl 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

vinyl 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

vinyl v1 -expect fetch_failed == 3
