varnishtest "h2 rapid reset"

barrier b1 sock 2 -cyclic
barrier b2 sock 5 -cyclic

server s1 {
	rxreq
	txresp
} -start

varnish v1 -cliok "param.set feature +http2"
varnish v1 -cliok "param.set debug +syncvsl"
varnish v1 -cliok "param.set h2_rapid_reset_limit 3"
varnish v1 -cliok "param.set h2_rapid_reset 5"

varnish v1 -vcl+backend {
	import vtc;

	sub vcl_recv {
		if (req.http.barrier) {
			vtc.barrier_sync(req.http.barrier);
		}
		vtc.barrier_sync("${b2_sock}");
	}

} -start

client c1 {
	stream 0 {
		rxgoaway
		expect goaway.err == ENHANCE_YOUR_CALM
	} -start

	stream 1 {
		txreq -hdr barrier ${b1_sock}
		barrier b1 sync
		txrst
	} -run
	stream 3 {
		txreq -hdr barrier ${b1_sock}
		barrier b1 sync
		txrst
	} -run
	stream 5 {
		txreq -hdr barrier ${b1_sock}
		barrier b1 sync
		txrst
	} -run
	stream 7 {
		txreq -hdr barrier ${b1_sock}
		barrier b1 sync
		txrst
	} -run

	barrier b2 sync
	stream 0 -wait
} -run

varnish v1 -expect sc_rapid_reset == 1

varnish v1 -cliok "param.set feature -vcl_req_reset"

client c2 {
	stream 0 {
		rxgoaway
		expect goaway.err == ENHANCE_YOUR_CALM
	} -start

	stream 1 {
		txreq
		txrst
	} -run
	stream 3 {
		txreq
		txrst
	} -run
	stream 5 {
		txreq
		txrst
	} -run
	stream 7 {
		txreq
		txrst
	} -run

	barrier b2 sync
	stream 0 -wait
} -run

varnish v1 -expect sc_rapid_reset == 2
