vtest "Test WS_Reset off-by-one when workspace is full"

server s1 {
	rxreq
	txresp
} -start

vinyl v1 -vcl+backend {
	import std;
	import vtc;

	sub vcl_recv {
		set req.http.ws-free1 = vtc.workspace_free(session);
		vtc.workspace_alloc(session, std.integer(req.http.ws-free1, 0));
		set req.http.ws-free2 = vtc.workspace_free(session);
		vtc.workspace_snapshot(session);
		vtc.workspace_reset(session);
		set req.http.ws-free3 = vtc.workspace_free(session);

		# Cover an obscure case in VRT_String() while here
		set req.http.bar = vtc.typesize(
			req.http.h1 + req.http.h2 + req.http.h3);
	}
} -start

logexpect l1 -v v1 -g request {
	expect * * ReqHeader {^ws-free1:}
	expect 0 = ReqHeader {^ws-free2: 0$}
	expect 0 = ReqHeader {^ws-free3: 0$}
} -start

client c1 {
	txreq -url /foo -hdr "h3: dd"
	rxresp
	expect resp.status == 200
} -run

logexpect l1 -wait
