vtest "Test non-transient rxbuf stevedore with LRU nuking"

barrier b1 sock 2 -cyclic

server s1 {
	rxreq
	txresp -body asdf
	rxreq
	expect req.http.X-Vinyl == 1005
	txresp -bodylen 1048000
	rxreq
	txresp -body ASDF
} -start

vinyl v1 -arg "-srxbuf=malloc,1m -smain=malloc,1m" -vcl+backend {
	import vtc;
	sub vcl_recv {
		if (req.url == "/1") {
			vtc.barrier_sync("${b1_sock}");
		}
	}
	sub vcl_backend_response {
		if (bereq.url == "/2") {
			set beresp.storage = storage.rxbuf;
		} else {
			set beresp.storage = storage.main;
		}
	}
}

vinyl v1 -cliok "param.set feature +http2"
vinyl v1 -cliok "param.reset h2_initial_window_size"
vinyl v1 -cliok "param.reset h2_rx_window_low_water"
vinyl v1 -cliok "param.set h2_rxbuf_storage rxbuf"
vinyl v1 -cliok "param.set vsl_mask +ExpKill"
vinyl v1 -cliok "param.set debug +syncvsl"

vinyl v1 -start

client c1 {
	stream 1 {
		txreq -req POST -url /1 -hdr "content-length" "2048" -nostrend
		txdata -datalen 2048
		rxresp
		expect resp.status == 200
	} -start
} -start

vinyl v1 -expect SM?.rxbuf.g_bytes >= 2048
vinyl v1 -expect SM?.Transient.g_bytes == 0
vinyl v1 -expect MAIN.n_lru_nuked == 0

barrier b1 sync
client c1 -wait

vinyl v1 -vsl_catchup

vinyl v1 -expect SM?.rxbuf.g_bytes == 0
vinyl v1 -expect SM?.Transient.g_bytes == 0
vinyl v1 -expect MAIN.n_lru_nuked == 0

client c2 {
	txreq -url /2
	rxresp
	expect resp.status == 200
	expect resp.bodylen == 1048000
} -run

vinyl v1 -vsl_catchup

vinyl v1 -expect SM?.rxbuf.g_bytes >= 1048000
vinyl v1 -expect MAIN.n_lru_nuked == 0

logexpect l1 -v v1 -g raw -q "Expkill ~ LRU" {
	expect * * Expkill xid=1005
} -start

client c3 {
	stream 1 {
		txreq -req POST -url /1 -hdr "content-length" "2048" -nostrend
		txdata -datalen 2048
		rxresp
		expect resp.status == 200
	} -start
} -start

logexpect l1 -wait

vinyl v1 -expect SM?.rxbuf.g_bytes >= 2048
vinyl v1 -expect SM?.rxbuf.g_bytes < 3000
vinyl v1 -expect SM?.Transient.g_bytes == 0
vinyl v1 -expect MAIN.n_lru_nuked == 1

barrier b1 sync
client c3 -wait

vinyl v1 -vsl_catchup

vinyl v1 -expect SM?.rxbuf.g_bytes == 0
vinyl v1 -expect SM?.Transient.g_bytes == 0
