varnishtest "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

varnish v1 -arg "-sdeprecated_persistent,${tmpdir}/_.per,5m" \
	   -arg "-p feature=+no_coredump" \
	-vcl+backend {} -start

varnish 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
varnish v1 -cliok "debug.persistent s0 sync"

# Tell server to continue
barrier b2 sync

# Get the result
client c1 -wait

varnish v1 -cliok "debug.persistent s0 dump"

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

delay 0.5

varnish v1 -cliok "panic.clear"

delay 0.5

# start again
varnish 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

varnish v1 -expectexit 0x40
