vtest "debug storage"

shell -err -expect {Error: Only one -sdebug instance supported} \
	"vinyld -b none -a ${tmpdir}/vtc.sock -n ${tmpdir}/v1 -sdebug -sdebug"

shell -err -expect {Error: -sdebug conflicting options} \
	"vinyld -b none -a ${tmpdir}/vtc.sock -n ${tmpdir}/v1 -sdebug,lessspace,maxspace=1KB" 

shell -err -expect {Error: Unknown BYTES} \
	"vinyld -b none -a ${tmpdir}/vtc.sock -n ${tmpdir}/v1 -sdebug,maxspace=1DJT"

# lessspace is implicitly tested in b00017.vtc

barrier b1 cond 2
barrier b2 cond 2

server s1 {
	rxreq
	txresp -bodylen 1024

	rxreq
	txresp -nolen -hdr "Content-Length: 1025"
	barrier b1 sync
	send_n 31 0123456789abcdef0123456789abcdef
	send_n  1 0123456789abcdef0123456789abcde
	barrier b2 sync
	non_fatal
	send "X"
} -start


vinyl v1 -arg "-sTransient=debug,maxspace=1KB" -vcl+backend {
	sub vcl_recv {
		return(pass);
	}
} -start

logexpect l1 -v v1 -q "BerespHeader:Content-Length eq 1025" {
	fail add *	End
	expect * * Storage	{^-sdebug: max_size=1024 reached}
	expect 0 = FetchError	{^Could not get storage}
	expect 0 = BackendClose	{close RX_BODY}
	fail clear
} -start

client c1 {
	txreq
	rxresp
	expect resp.bodylen == 1024

	txreq
	rxresphdrs
	expect resp.status == 200
	expect resp.http.Content-Length == 1025
	barrier b1 sync
	rxrespbody -max 1023
	barrier b2 sync
	non_fatal
	rxrespbody -max 1
	expect_close
} -run

logexpect l1 -wait
