[master] 8fc1b2c3a vtest: Add "option timeout" to adjust the timeout per test case
Nils Goroll
nils.goroll at uplex.de
Tue May 28 08:41:05 UTC 2024
commit 8fc1b2c3af3eea0aa0a424fdc6bb76788a9f5661
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Tue May 28 10:38:03 2024 +0200
vtest: Add "option timeout" to adjust the timeout per test case
diff --git a/bin/varnishtest/cmds.h b/bin/varnishtest/cmds.h
index 3b8a9e9fd..257372b11 100644
--- a/bin/varnishtest/cmds.h
+++ b/bin/varnishtest/cmds.h
@@ -45,6 +45,7 @@ CMD_GLOBAL(include)
#endif
CMD_TOP(client)
CMD_TOP(feature)
+CMD_TOP(option)
CMD_TOP(filewrite)
CMD_TOP(haproxy)
#ifdef VTEST_WITH_VTC_LOGEXPECT
diff --git a/bin/varnishtest/tests/a00000.vtc b/bin/varnishtest/tests/a00000.vtc
index 2d3604f24..423e8e23c 100644
--- a/bin/varnishtest/tests/a00000.vtc
+++ b/bin/varnishtest/tests/a00000.vtc
@@ -1,5 +1,8 @@
varnishtest "Test varnishtest itself"
+option timeout 60s
+option timeout x1.1
+
shell -exit 1 -expect {varnishtest [options]} {varnishtest -h}
shell -exit 1 -match {-D.*Define macro} {varnishtest -h}
diff --git a/bin/varnishtest/vtc_misc.c b/bin/varnishtest/vtc_misc.c
index 64d7b506d..52ec902b3 100644
--- a/bin/varnishtest/vtc_misc.c
+++ b/bin/varnishtest/vtc_misc.c
@@ -660,3 +660,52 @@ cmd_feature(CMD_ARGS)
return;
}
}
+
+static void
+set_timeout(struct vtclog *vl, const char *val)
+{
+ double num;
+ char *s = NULL;
+
+ if (val == NULL || *val == '\0') {
+ vtc_fatal(vl, "FAIL test, missing \"option timeout\" value");
+ return;
+ }
+ if (*val == 'x') {
+ num = strtod(val + 1, &s);
+ num *= vtc_maxdur;
+ } else
+ num = VNUM_duration(val);
+
+ if (isnan(num) || (s != NULL && *s != '\0')) {
+ vtc_fatal(vl, "FAIL test, invalid \"option timeout\": %s", val);
+ return;
+ }
+ vtc_maxdur = num;
+ vtc_log(vl, 4, "new timeout %.2f", vtc_maxdur);
+}
+
+/* SECTION: option <option> <value>
+ *
+ * Set varnishtest options
+ *
+ * timeout <duration>
+ * Override -t argument
+ * timeout x<factor>
+ * Scale timeout by a <factor>
+ */
+
+void v_matchproto_(cmd_f)
+cmd_option(CMD_ARGS)
+{
+
+ (void)priv;
+
+ if (av == NULL)
+ return;
+ av++;
+ if (!strcmp(av[0], "timeout"))
+ set_timeout(vl, av[1]);
+ else
+ vtc_fatal(vl, "FAIL test, unknown option: %s", av[0]);
+}
More information about the varnish-commit
mailing list