vtest "test iovec flush counter"

server s0 {
	rxreq
	txresp
} -dispatch

# http1_iovs
# Simple request/response

vinyl v1 -vcl+backend {} -start

vinyl v1 -cliok "param.set http1_iovs 30"

client c1 {
	txreq
	rxresp
} -run

vinyl v1 -expect MAIN.http1_iovs_flush == 0

# Decreasing http1_iovs causes premature flushes
vinyl v1 -cliok "param.set http1_iovs 5"

client c1 {
	txreq
	rxresp
} -run

vinyl v1 -expect MAIN.http1_iovs_flush > 0

##################################################
# Increase number of headers on fetch side

vinyl v1 -cliok "param.set http1_iovs 30"

vinyl v1 -stop
vinyl v1 -vcl+backend {
	sub vcl_backend_fetch {
		set bereq.http.hdr1 = "hdr";
		set bereq.http.hdr2 = "hdr";
		set bereq.http.hdr3 = "hdr";
		set bereq.http.hdr4 = "hdr";
		set bereq.http.hdr5 = "hdr";
		set bereq.http.hdr6 = "hdr";
		set bereq.http.hdr7 = "hdr";
		set bereq.http.hdr8 = "hdr";
		set bereq.http.hdr9 = "hdr";
		set bereq.http.hdr10 = "hdr";
		set bereq.http.hdr11 = "hdr";
		set bereq.http.hdr12 = "hdr";
		set bereq.http.hdr13 = "hdr";
		set bereq.http.hdr14 = "hdr";
		set bereq.http.hdr15 = "hdr";
		set bereq.http.hdr16 = "hdr";
		set bereq.http.hdr17 = "hdr";
		set bereq.http.hdr18 = "hdr";
		set bereq.http.hdr19 = "hdr";
		set bereq.http.hdr20 = "hdr";
	}
} -start


client c1 {
	txreq
	rxresp
} -run

# http1_iovs parameter does not affect fetch
vinyl v1 -expect MAIN.http1_iovs_flush == 0

#####################################################
# Increase number of headers on deliver side

vinyl v1 -stop
vinyl v1 -vcl+backend {
	sub vcl_deliver {
		set resp.http.hdr1 = "hdr";
		set resp.http.hdr2 = "hdr";
		set resp.http.hdr3 = "hdr";
		set resp.http.hdr4 = "hdr";
		set resp.http.hdr5 = "hdr";
		set resp.http.hdr6 = "hdr";
		set resp.http.hdr7 = "hdr";
		set resp.http.hdr8 = "hdr";
		set resp.http.hdr9 = "hdr";
		set resp.http.hdr10 = "hdr";
		set resp.http.hdr11 = "hdr";
		set resp.http.hdr12 = "hdr";
		set resp.http.hdr13 = "hdr";
		set resp.http.hdr14 = "hdr";
		set resp.http.hdr15 = "hdr";
		set resp.http.hdr16 = "hdr";
		set resp.http.hdr17 = "hdr";
		set resp.http.hdr18 = "hdr";
		set resp.http.hdr19 = "hdr";
		set resp.http.hdr20 = "hdr";
	}
} -start

vinyl v1 -cliok "param.set http1_iovs 30"

client c1 {
	txreq
	rxresp
} -run

# http1_iovs parameter affects deliver
vinyl v1 -expect MAIN.http1_iovs_flush > 0

##################################################
# Compare with workspace_thread
# 0.5k is enough for simplest request/response

vinyl v1 -cliok "param.reset http1_iovs"
vinyl v1 -stop

vinyl v1 -cliok "param.set workspace_thread 0.5k"
vinyl v1 -vcl+backend {} -start

client c1 {
	txreq
	rxresp
} -run

vinyl v1 -expect MAIN.http1_iovs_flush == 0

# Increase number of headers on fetch side
vinyl v1 -stop
vinyl v1 -vcl+backend {
	sub vcl_backend_fetch {
		set bereq.http.hdr1 = "hdr";
		set bereq.http.hdr2 = "hdr";
		set bereq.http.hdr3 = "hdr";
		set bereq.http.hdr4 = "hdr";
		set bereq.http.hdr5 = "hdr";
		set bereq.http.hdr6 = "hdr";
		set bereq.http.hdr7 = "hdr";
		set bereq.http.hdr8 = "hdr";
		set bereq.http.hdr9 = "hdr";
		set bereq.http.hdr10 = "hdr";
		set bereq.http.hdr11 = "hdr";
		set bereq.http.hdr12 = "hdr";
		set bereq.http.hdr13 = "hdr";
		set bereq.http.hdr14 = "hdr";
		set bereq.http.hdr15 = "hdr";
		set bereq.http.hdr16 = "hdr";
		set bereq.http.hdr17 = "hdr";
		set bereq.http.hdr18 = "hdr";
		set bereq.http.hdr19 = "hdr";
		set bereq.http.hdr20 = "hdr";
	}
} -start

client c1 {
	txreq
	rxresp
} -run

# workspace_thread parameter affects fetch
vinyl v1 -expect MAIN.http1_iovs_flush > 0

# Increase number of headers on deliver side
vinyl v1 -stop
vinyl v1 -vcl+backend {
	sub vcl_deliver {
		set resp.http.hdr1 = "hdr";
		set resp.http.hdr2 = "hdr";
		set resp.http.hdr3 = "hdr";
		set resp.http.hdr4 = "hdr";
		set resp.http.hdr5 = "hdr";
		set resp.http.hdr6 = "hdr";
		set resp.http.hdr7 = "hdr";
		set resp.http.hdr8 = "hdr";
		set resp.http.hdr9 = "hdr";
		set resp.http.hdr10 = "hdr";
		set resp.http.hdr11 = "hdr";
		set resp.http.hdr12 = "hdr";
		set resp.http.hdr13 = "hdr";
		set resp.http.hdr14 = "hdr";
		set resp.http.hdr15 = "hdr";
		set resp.http.hdr16 = "hdr";
		set resp.http.hdr17 = "hdr";
		set resp.http.hdr18 = "hdr";
		set resp.http.hdr19 = "hdr";
		set resp.http.hdr20 = "hdr";
	}
} -start

client c1 {
	txreq
	rxresp
} -run

# workspace_thread parameter affects deliver
vinyl v1 -expect MAIN.http1_iovs_flush > 0
