vtest "client h2 send timeouts"

server s1 {
	rxreq
	txresp -bodylen 12345
} -start

vinyl v1 -cliok "param.set feature +http2"
vinyl v1 -vcl+backend {
	sub vcl_recv {
		if (req.url ~ "synth") {
			return (synth(200));
		}
	}
} -start

# coverage for send_timeout with c1

vinyl v1 -cliok "param.set send_timeout 1"

logexpect l1 -v v1 {
	expect * * Debug "Hit send_timeout"
} -start

client c1 {
	txpri

	stream 0 {
		rxsettings
		expect settings.ack == false
		txsettings -ack
		txsettings -winsize 1000
		rxsettings
		expect settings.ack == true
	} -run

	stream 1 {
		txreq
		rxhdrs
		rxdata
		# keep the stream idle for 2 seconds
		delay 2
		txwinup -size 256
		# too late
		rxrst
		expect rst.err == CANCEL
	} -run

} -run

logexpect l1 -wait

# coverage for h2_window_timeout with c2

vinyl v1 -cliok "param.set h2_window_timeout 1"
vinyl v1 -cliok "param.reset send_timeout"

logexpect l2 -v v1 {
	expect * * Debug "Hit h2_window_timeout"
} -start

client c2 {
	txpri

	stream 0 {
		rxsettings
		expect settings.ack == false
		txsettings -ack
		txsettings -winsize 1000
		rxsettings
		expect settings.ack == true
	} -run

	stream 1 {
		txreq -nostrend -url "/synth"
	} -run

	stream 3 {
		txreq
		rxhdrs
		rxdata
		# keep the stream idle for 2 seconds
		delay 2
		rxrst
		expect rst.err == CANCEL
	} -run

	stream 1 {
		txdata
	} -run
} -run

logexpect l2 -wait

# coverage for h2_window_timeout change with c3

barrier b3 cond 2

logexpect l3 -v v1 {
	expect * * Debug "Hit h2_window_timeout"
} -start

client c3 {
	txpri

	stream 0 {
		rxsettings
		expect settings.ack == false
		txsettings -ack
		txsettings -winsize 1000
		rxsettings
		expect settings.ack == true
	} -run

	stream 1 {
		txreq -nostrend -url "/synth"
	} -run

	stream 3 {
		txreq
		rxhdrs
		rxdata
		# keep the stream idle for 2 seconds
		barrier b3 sync
		delay 2
		rxrst
		expect rst.err == CANCEL
	} -run

	stream 1 {
		txdata
	} -run
} -start

barrier b3 sync
vinyl v1 -cliok "param.reset h2_window_timeout"

client c3 -wait
logexpect l3 -wait
