varnishtest "workspace overflow with failed backend fetch"

varnish v1 -vcl {
	import vtc;

	backend default {
		.host = "${bad_backend}";
	}

	sub vcl_backend_fetch {
		# avoid LostHeader      b Host: %s
		set bereq.http.Host = "127.0.0.1";
		vtc.workspace_alloc(backend, vtc.workspace_free(backend));
	}

	sub vcl_backend_error {
		# At this point we got no workspace to stringify
		# the non-standard status 299, but we will leave
		# the const "Unknown HTTP Status" reason
		set beresp.status = 299;
	}

} -start

logexpect l1 -v v1 -g raw {
	expect * 1002 FetchError   {^out of workspace}
	expect * =    BerespStatus {^503}
	expect * =    BerespReason {^Backend fetch failed}
	expect * =    Error        {^out of workspace [(]bo[)]}
	expect * =    LostHeader   {^Date:}
	expect * =    Error        {^out of workspace [(]bo[)]}
	expect * =    LostHeader   {^299}
} -start

client c1 {
	txreq -url "/"
	rxresp
	expect resp.status == 503
	expect resp.reason == "Unknown HTTP Status"
} -run

logexpect l1 -wait
varnish v1 -expect ws_backend_overflow == 1
