vtest "Test address remapping"

feature persistent_storage

# VM-remapping is too random on OSX
feature cmd {test $(uname) != "Darwin"}
# Same on some hardened Linux
feature cmd "test ! -c /dev/grsec"

server s1 {
	rxreq
	txresp
} -start

shell "rm -f ${tmpdir}/_.per?"

vinyl v1 \
	-arg "-pfeature=+wait_silo" \
	-arg "-sdeprecated_persistent,${tmpdir}/_.per1,5m" \
	-arg "-sdeprecated_persistent,${tmpdir}/_.per2,5m" \
	-syntax 4.0 \
	-vcl+backend {
	sub vcl_backend_response {
		set beresp.storage = storage.s0;
	}
} -start

vinyl v1 -stop

vinyl v1 -start

client c1 {
	txreq -url "/"
	rxresp
	expect resp.status == 200
	expect resp.http.X-Vinyl == "1001"
} -run

vinyl v1 -cliok "storage.list"
vinyl v1 -cliok "debug.persistent s0 dump"
vinyl v1 -cliok "debug.persistent s0 sync"
vinyl v1 -stop

server s1 {
	rxreq
	txresp -status 400 -reason "Persistent Object Not Found"
} -start


vinyl v2 \
	-arg "-pfeature=+wait_silo" \
	-arg "-sdeprecated_persistent,${tmpdir}/_.per2,5m" \
	-arg "-sdeprecated_persistent,${tmpdir}/_.per1,5m" \
	-vcl+backend { } -start

client c1 -connect ${v2_sock} {
	txreq -url "/"
	rxresp
	expect resp.reason != "Persistent Object Not Found"
	expect resp.status == 200
	expect resp.http.X-Vinyl == "1001 1002"
} -run

# shell "rm -f /tmp/__v1/_.per"
