varnishtest "VMOD purge"

server s1 -repeat 12 {
	rxreq
	txresp
} -start

varnish v1 -cliok "param.set thread_pools 1"
varnish v1 -cliok "param.set vsl_mask +ExpKill"
varnish v1 -vcl+backend {
	import purge;

	sub vcl_miss {
		if (req.url == "miss") { purge.hard(); }
	}
	sub vcl_hit {
		if (req.url == "hit") { purge.hard(); }
	}
} -start

varnish v1 -cliok "param.set timeout_idle 2"

logexpect l0 -v v1 -g raw {
	expect * 0 ExpKill	"EXP_Expired xid=1002"
} -start

logexpect l2 -v v1 -g raw {
	expect * 1002	Begin		"bereq 1001 fetch"
} -start

logexpect l1 -v v1 {

	expect * 1003	VCL_call	HIT
	expect 0 =	VCL_return	deliver

	expect * 1004	VCL_call	MISS
	expect 0 =	VCL_return	fetch

} -start

client c1 {
	txreq -url hit
	rxresp
	expect resp.status == 200

	txreq -url hit
	rxresp
	expect resp.status == 200

	txreq -url miss
	rxresp
	expect resp.status == 200
} -run

logexpect l0 -wait
logexpect l2 -wait

varnish v1 -errvcl "Not available in subroutine 'vcl_purge'" {
	import purge;

	sub vcl_purge {
		if (req.url == "purge") { purge.hard(); }
	}
}

varnish v1 -errvcl "Not available in subroutine 'vcl_pass'" {
	import purge;

	sub vcl_pass {
		if (req.url == "pass") { purge.hard(); }
	}
}

varnish v1 -errvcl "Not available in subroutine 'vcl_deliver'" {
	import purge;

	sub vcl_deliver {
		if (req.url == "deliver") { purge.hard(); }
	}
}

varnish v1 -errvcl "Not available in subroutine 'vcl_synth'" {
	import purge;

	sub vcl_synth {
		if (req.url == "synth") { purge.hard(); }
	}
}

varnish v1 -errvcl "Not available in subroutine 'vcl_backend_fetch'" {
	import purge;

	sub vcl_backend_fetch {
		if (bereq.url == "fetch") { purge.hard(); }
	}
}

varnish v1 -errvcl "Not available in subroutine 'vcl_backend_error'" {
	import purge;

	sub vcl_backend_error {
		if (bereq.url == "error") { purge.hard(); }
	}
}

varnish v1 -errvcl "Not available in subroutine 'vcl_backend_response'" {
	import purge;

	sub vcl_backend_response {
		if (bereq.url == "response") { purge.hard(); }
	}
}