vtest "Low req.body streaming pressure on storage"

server s0 {
	rxreq
	txresp -status 200
	expect req.bodylen == 100000
} -dispatch

vinyl v1 -vcl+backend {
	import std;

	sub vcl_recv {
		set req.storage = storage.s0;
		if (req.http.cache) {
			std.cache_req_body(100000b);
		}
	}
} -start

# explicit setting to be robust against changes to the default value
vinyl v1 -cliok "param.set fetch_chunksize 16k"

# chunked req.body streaming uses approximately one fetch_chunksize'd chunk
client c1 {
	txreq -req PUT -hdr "Transfer-encoding: chunked"
	chunkedlen 100000
	chunkedlen 0
	rxresp
	expect resp.status == 200
} -run

# in practice a little over fetch_chunksize is allocated
vinyl v1 -expect SM?.s0.c_bytes < 20000
vinyl v1 -vsl_catchup

# reset s0 counters
vinyl v1 -stop
vinyl v1 -start
vinyl v1 -expect SM?.s0.c_bytes == 0

# content-length req.body streaming also needs one chunk
client c2 {
	txreq -req PUT -bodylen 100000
	rxresp
	expect resp.status == 200
} -run

vinyl v1 -expect SM?.s0.c_bytes < 20000
vinyl v1 -vsl_catchup

# reset s0 counters
vinyl v1 -stop
vinyl v1 -start

# chunked req.body caching allocates storage for the entire body
client c3 {
	txreq -req PUT -hdr "cache: body" -hdr "Transfer-encoding: chunked"
	chunkedlen 100000
	chunkedlen 0
	rxresp
	expect resp.status == 200
} -run

vinyl v1 -expect SM?.s0.c_bytes > 100000
vinyl v1 -vsl_catchup

# reset s0 counters
vinyl v1 -stop
vinyl v1 -start

# content-length req.body caching allocates storage for the entire body
client c4 {
	txreq -req PUT -hdr "cache: body" -bodylen 100000
	rxresp
	expect resp.status == 200
} -run

vinyl v1 -expect SM?.s0.c_bytes > 100000
vinyl v1 -vsl_catchup
