varnishtest "shard director Unhealthy"

server s1 {
} -start

server s2 {
	rxreq
	expect req.http.healthy == "true"
	txresp -body "ieQu2qua"
} -start

server s3 {
	rxreq
	expect req.http.healthy == "true"
	txresp -body "xiuFi3Pe"
	rxreq
	expect req.http.healthy == "true"
	txresp -body "xiuFi3Pe"
} -start

varnish v1 -vcl+backend {
	import std;
	import directors;

	sub vcl_init {
		new vd = directors.shard();
		vd.debug(3);
		vd.add_backend(s1);
		vd.add_backend(s2);
		vd.add_backend(s3);
		vd.reconfigure(25);
	}

	sub vcl_recv {
		if (req.url == "/warmup") {
			# key for which the order is s3->s1->s2
			# we do not want to hit s1/s2 because they are down
			set req.backend_hint = vd.backend(by=KEY,
			    key=192192123, warmup=1.0);
		} else {
			# key for which the order is s1->s2->s3
			set req.backend_hint = vd.backend(by=KEY,
			    key=1756955383);
		}
		set req.http.healthy = std.healthy(req.backend_hint);
		return(pass);
	}
} -start

varnish v1 -cliok "backend.set_health s1 sick"

client c1 {
	txreq
	rxresp
	expect resp.body == "ieQu2qua"
} -run

varnish v1 -cliok "backend.set_health s2 sick"

client c1 {
	txreq
	rxresp
	expect resp.body == "xiuFi3Pe"
	txreq -url "/warmup"
	rxresp
	expect resp.body == "xiuFi3Pe"
} -run
