varnishtest "Test actual client workspace overflow"

server s1 {
	rxreq
	txresp

	rxreq
	txresp

	rxreq
	txresp
} -start

varnish v1 -vcl+backend {
	import vtc;
	sub vcl_deliver {
		vtc.workspace_alloc(client, -192);

		if (req.url ~ "/bar") {
			set resp.http.x-foo = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
			vtc.workspace_alloc(client, -10);
		}
		else if (req.url ~ "/baz") {
			set resp.http.x-foo = regsub(req.url, "baz", "baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz");
		}
		set resp.http.x-of = vtc.workspace_overflowed(client);
	}
} -start

client c1 {
	txreq -url /foo
	rxresp
	expect resp.status == 200
	expect resp.http.x-of == "false"

	txreq -url /bar
	rxresp
	expect resp.status == 500
	expect resp.http.x-of == <undef>
} -run

client c2 {
	txreq -url /baz
	rxresp
	expect resp.status == 500
	expect resp.http.x-of == <undef>
} -run


varnish v1 -expect client_resp_500 == 2
varnish v1 -expect ws_client_overflow == 2
