vtest "pipe timeouts"

server s1 {
	rxreq
	txresp -hdr "transfer-encoding: chunked"
	delay 1.1
	close

	loop 3 {
		accept
		rxreq
		txresp -hdr "transfer-encoding: chunked"
		expect_close
	}

	accept
	non_fatal
	rxreq
	txresp -hdr "transfer-encoding: chunked"
	loop 20 {
		chunkedlen 1
		delay 0.1
	}
} -start

vinyl v1 -cliok "param.set pipe_timeout 0s"
vinyl v1 -cliok "param.set pipe_task_deadline 0s"
vinyl v1 -vcl+backend {
	sub vcl_recv {
		return (pipe);
	}

	sub vcl_pipe {
		set bereq.task_deadline = 1.1s;
		if (req.method != "TMO") {
			unset bereq.task_deadline;
		}
	}
} -start

logexpect l1 -v v1 -g raw -q SessClose {
	expect 1000 * SessClose {^TX_PIPE 1\.}
	expect 1003 * SessClose {^RX_TIMEOUT 0\.}
	expect 1006 * SessClose {^RX_TIMEOUT 1\.}
	expect 1009 * SessClose {^RX_TIMEOUT 1\.}
	expect 1012 * SessClose {^RX_TIMEOUT 1\.}
} -start

client c1 {
	non_fatal
	txreq -method PIPE
	rxresp
} -run

vinyl v1 -cliok "param.set pipe_timeout 500ms"
vinyl v1 -cliok "param.set pipe_task_deadline 0s"
client c1 -run

vinyl v1 -cliok "param.set pipe_timeout 0s"
vinyl v1 -cliok "param.set pipe_task_deadline 1.1s"
client c1 -run

vinyl v1 -cliok "param.set pipe_timeout 0s"
vinyl v1 -cliok "param.set pipe_task_deadline 0s"

client c2 {
	non_fatal
	txreq -method TMO
	rxresp
} -run

vinyl v1 -cliok "param.set pipe_timeout 500ms"
vinyl v1 -cliok "param.set pipe_task_deadline 1.1s"
client c1 -run

logexpect l1 -wait

vinyl v1 -expect MAIN.s_pipe == 5
vinyl v1 -expect MAIN.sc_tx_pipe == 1
vinyl v1 -expect MAIN.sc_rx_timeout == 4
