[master] 5e72440e0 Test that VRT_fail from an object constructor works as expected

Nils Goroll nils.goroll at uplex.de
Mon Sep 19 13:44:06 UTC 2022


commit 5e72440e0f0dbfa285971c036afa3a1cbb514fd9
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Tue Sep 13 19:15:58 2022 +0200

    Test that VRT_fail from an object constructor works as expected

diff --git a/bin/varnishtest/tests/m00000.vtc b/bin/varnishtest/tests/m00000.vtc
index 3aed21140..cc78c3c1f 100644
--- a/bin/varnishtest/tests/m00000.vtc
+++ b/bin/varnishtest/tests/m00000.vtc
@@ -165,6 +165,14 @@ varnish v1 -errvcl {Failed from VCL} {
 	}
 }
 
+varnish v1 -errvcl {Failed initialization} {
+	import debug;
+	backend none none;
+	sub vcl_init {
+		new fails = debug.obj("fail");
+	}
+}
+
 varnish v1 -cliok "param.set vcc_feature +allow_inline_c"
 varnish v1 -vcl {
 	import vtc;
@@ -289,7 +297,7 @@ varnish v1 -cliok "vcl.list"
 
 varnish v1 -expect vmods == 3
 
-varnish v1 -cliok "vcl.discard vcl[1-9]"
+varnish v1 -cliok "vcl.discard vcl[1-9] vcl10"
 varnish v1 -cliok "vcl.list"
 varnish v1 -cliok "debug.vmod"
 
diff --git a/vmod/vmod_debug.vcc b/vmod/vmod_debug.vcc
index 6f9d8d71d..90be677d6 100644
--- a/vmod/vmod_debug.vcc
+++ b/vmod/vmod_debug.vcc
@@ -73,6 +73,8 @@ $Object obj(STRING string="default", ENUM { one, two, three } number=one)
 
 Test object
 
+Fail for string="fail".
+
 .. NOTE: .enum before .foo as part of test r01332.vtc
 $Method VOID .enum(ENUM { phk, des, kristian, mithrandir, martin })
 
diff --git a/vmod/vmod_debug_obj.c b/vmod/vmod_debug_obj.c
index 94331f047..28a6bfa00 100644
--- a/vmod/vmod_debug_obj.c
+++ b/vmod/vmod_debug_obj.c
@@ -60,6 +60,10 @@ xyzzy_obj__init(VRT_CTX, struct xyzzy_debug_obj **op,
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	AN(op);
 	AZ(*op);
+
+	if (! strcmp(s, "fail")) {
+		VRT_fail(ctx, "failing as requested");
+	}
 	ALLOC_OBJ(o, VMOD_DEBUG_OBJ_MAGIC);
 	AN(o);
 	*op = o;


More information about the varnish-commit mailing list