vtest "Test vmod failure in vcl_init{}"

server s1 {
	rxreq
	txresp
} -start

vinyl v1 -vcl+backend { } -start

logexpect l1 -v v1 -g raw {
	fail add * VCL_Log "Should not happen"
	expect * 0 VCL_Log "Should happen first"
	expect 0 0 VCL_Log "Should happen second"
	fail clear
} -start

vinyl v1 -errvcl "Forced failure" {

	import debug;
	import std;

	backend default {
		.host = "${s1_addr}";
	}

	sub vcl_init {
		std.log("Should happen first");
		debug.fail();
		std.log("Should not happen");
	}

	sub vcl_fini {
		std.log("Should happen second");
	}
}

logexpect l1 -wait

vinyl v1 -cliok "param.set nuke_limit 42"

vinyl v1 -errvcl "nuke_limit is not the answer." {

	import debug;

	backend default {
		.host = "${s1_addr}";
	}
}

client c1 {
	txreq
	rxresp
	expect resp.status == 200
} -run
