vtest "Test bans_req counter on persistent reload - #1225"

feature persistent_storage

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

server s1 {
	rxreq
	expect req.url == "/"
	txresp -hdr "Foo: foo"
} -start

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

vinyl v1 -cliok ban.list

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

# Count of 1 here (magic ban only)
vinyl v1 -expect bans == 1
vinyl v1 -cliok "ban req.url == /"
vinyl v1 -cliok ban.list

# Count of 2 here (our + magic ban)
vinyl v1 -expect bans == 2
vinyl v1 -expect bans_req == 1
vinyl v1 -stop
server s1 -wait

server s1 {
	rxreq
	expect req.url == "/"
	txresp -hdr "Foo: bar"
} -start

vinyl v1 -start

vinyl v1 -cliok ban.list

# Count of >2 here, ours plus magic bans from 2 startups
vinyl v1 -expect bans >= 2

client c1 {
	txreq -url "/"
	rxresp
	expect resp.status == 200
	expect resp.http.foo == "bar"
} -run

vinyl v1 -cliok ban.list
# Count of 1 here
vinyl v1 -expect bans == 1
vinyl v1 -expect bans_req == 0

vinyl v1 -stop
