varnishtest "concurrent pipe limit"

barrier b1 cond 2
barrier b2 cond 2
barrier b3 cond 2
barrier b4 cond 2

server s1 {
	rxreq
	barrier b1 sync
	barrier b2 sync
	txresp
} -start

server s2 {
	rxreq
	barrier b3 sync
	barrier b4 sync
	txresp
} -start

varnish v1 -vcl+backend {
	sub vcl_recv {
		if (req.url == "/c1") {
			set req.backend_hint = s1;
		}
		elsif (req.url == "/c2") {
			set req.backend_hint = s2;
		}
		return (pipe);
	}
} -start

varnish v1 -expect MAIN.n_pipe == 0

client c1 {
	txreq -url "/c1"
	rxresp
	expect resp.status == 200
} -start

barrier b1 sync

varnish v1 -expect MAIN.n_pipe == 1

client c2 {
	txreq -url "/c2"
	rxresp
	expect resp.status == 200
} -start

barrier b3 sync
varnish v1 -expect MAIN.n_pipe == 2

varnish v1 -cliok "param.set pipe_sess_max 2"

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

barrier b2 sync
varnish v1 -expect MAIN.n_pipe == 1
barrier b4 sync
varnish v1 -expect MAIN.n_pipe == 0
varnish v1 -expect MAIN.pipe_limited == 1
