vtest "test reload of object spanning incomplete segment"

feature persistent_storage
feature disable_aslr

barrier b1 cond 2
barrier b2 cond 2

server s1 {
	rxreq
	expect req.url == "/1"
	send "HTTP/1.1 200 OK\n"
	send "Transfer-encoding: chunked\n"
	send "\n"
	chunkedlen 32
	# Tell top-level that it can sync the stevedore
	barrier b1 sync
	# Top-level tells us it has synched the stevedore
	barrier b2 sync
	chunkedlen 32
	chunkedlen 0
	accept

	rxreq
	expect req.url == "/2"
	txresp -bodylen 100

	rxreq
	expect req.url == "/1"
	txresp -bodylen 48
} -start

vinyl v1 -arg "-sdeprecated_persistent,${tmpdir}/_.per,5m" \
	-vcl+backend {} -start

vinyl v1 -cliok "debug.fragfetch 32"

client c1 {
	txreq -url "/1"
	rxresp
	expect resp.bodylen == 64
} -start

# Wait for first chunk to have been sent
barrier b1 sync
delay .2

# Sync the stevedore, so the next chunk ends up i segment 2
vinyl v1 -cliok "debug.persistent s0 sync"

# Tell server to continue
barrier b2 sync

# Get the result
client c1 -wait

vinyl v1 -cliok "param.set feature +no_coredump"

vinyl v1 -cliok "debug.persistent s0 dump"

# Panic worker so second segment does not get closed
vinyl v1 -clierr 400 "debug.panic.worker"

delay 0.5

vinyl v1 -cliok "panic.clear"

delay 0.5

# start again
vinyl v1 -start

client c1 {
	# Make sure there is not a valid "struct storage" in second seg.
	txreq -url "/2"
	rxresp
	expect resp.bodylen == 100

	# Fetch the vampire object and see how that goes...
	txreq -url "/1"
	rxresp
	expect resp.bodylen == 48
} -run

vinyl v1 -expectexit 0x40
