varnishtest "#1284 - Test resource cleanup after STV_NewObject fail in fetch"

server s1 {
	rxreq
	expect req.url == "/obj1"
	txresp -bodylen 1048290
	rxreq
	expect req.url == "/obj2"
	txresp -hdr "Long: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" -hdr "Long2: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
} -start

varnish v1 \
	-arg "-p nuke_limit=0" \
	-arg "-sTransient=default,1m" \
	-syntax 4.0 \
	-vcl+backend {
	sub vcl_backend_response {
		set beresp.do_stream = false;
		set beresp.storage = storage.Transient;
		# Unset Date header to not change the object sizes
		unset beresp.http.Date;
	}
} -start

varnish v1 -cliok "param.set debug +syncvsl"

delay .1

client c1 {
	# Fill transient
	txreq -url "/obj1"
	rxresp
	expect resp.status == 200
} -run

delay .1

varnish v1 -expect SM?.Transient.g_bytes > 1048000
varnish v1 -expect SM?.Transient.g_space < 200

client c1 {
	# No space for this object (more than 256 bytes in headers). Don't wait
	# for reply as Varnish will not send one due to Transient full.
	txreq -url "/obj2"
	delay 1
} -run

# Three failures, one for obj2, one for vcl_backend_error{}, one for synth objcore
varnish v1 -expect SM?.Transient.c_fail == 3

client c1 {
	# Check that Varnish is still alive
	txreq -url "/obj1"
	rxresp
	expect resp.status == 200
} -run
