pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/41640?usp=email )


Change subject: StatsD_Checker: Abort on expectancy failure with clear status 
message
......................................................................

StatsD_Checker: Abort on expectancy failure with clear status message

Before this commit, a statsd expect failure would let the test continue
the test for a while and then finally log a rellay generic timeout
message, which makes really difficult to understand what's going on and
why is the test failing.

Let's terminate the test early if a test expectation fails, so it's a
lot easier to debug.
Add an extra param to be able to use the API for test logic to check the
state without failing/aborting. This is not really used anywhere so far
but the API was built this way and I indeed think it may be handy in the
future.

Change-Id: Ibc3d079c2a45aa22f9e2e42d75109cae66530f86
---
M library/StatsD_Checker.ttcnpp
1 file changed, 24 insertions(+), 12 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/40/41640/1

diff --git a/library/StatsD_Checker.ttcnpp b/library/StatsD_Checker.ttcnpp
index 081e6e1..9d0d823 100644
--- a/library/StatsD_Checker.ttcnpp
+++ b/library/StatsD_Checker.ttcnpp
@@ -90,7 +90,11 @@

 signature STATSD_reset();
 signature STATSD_snapshot(in StatsDMetricKeys keys, in boolean 
since_last_snapshot) return StatsDMetrics;
-signature STATSD_expect(in StatsDExpects expects, in boolean wait_converge, in 
boolean use_snapshot, in StatsDMetrics snapshot) return boolean;
+signature STATSD_expect(in StatsDExpects expects,
+                       in boolean wait_converge,
+                       in boolean abort_on_failure,
+                       in boolean use_snapshot,
+                       in StatsDMetrics snapshot) return boolean;

 type port STATSD_PROC_PT procedure {
        inout STATSD_reset, STATSD_snapshot, STATSD_expect;
@@ -106,6 +110,7 @@
        var boolean since_last_snapshot;
        var StatsDExpects expects;
        var boolean wait_converge;
+       var boolean abort_on_failure;
        var boolean use_snapshot;
        var StatsDMetrics snapshot;
        var Result res;
@@ -149,9 +154,9 @@
                        snapshot := f_statsd_checker_snapshot(keys, 
since_last_snapshot);
                        STATSD_PROC.reply(STATSD_snapshot:{keys, 
since_last_snapshot} value snapshot) to vc_conn;
                        }
-               [] STATSD_PROC.getcall(STATSD_expect:{?, ?, ?, ?}) -> 
param(expects, wait_converge, use_snapshot, snapshot) sender vc_conn {
-                       var boolean success := f_statsd_checker_expect(expects, 
wait_converge, use_snapshot, snapshot);
-                       STATSD_PROC.reply(STATSD_expect:{expects, 
wait_converge, use_snapshot, snapshot} value success) to vc_conn;
+               [] STATSD_PROC.getcall(STATSD_expect:{?, ?, ?, ?, ?}) -> 
param(expects, wait_converge, abort_on_failure, use_snapshot, snapshot) sender 
vc_conn {
+                       var boolean success := f_statsd_checker_expect(expects, 
wait_converge, abort_on_failure, use_snapshot, snapshot);
+                       STATSD_PROC.reply(STATSD_expect:{expects, 
wait_converge, abort_on_failure, use_snapshot, snapshot} value success) to 
vc_conn;
                        }
                }
        }
@@ -318,6 +323,7 @@

 private function f_statsd_checker_expect(StatsDExpects expects,
                                         boolean wait_converge := false,
+                                        boolean abort_on_failure := true,
                                         boolean use_snapshot := false,
                                         StatsDMetrics snapshot := {}) runs on 
StatsD_Checker_CT return boolean {
        var default t;
@@ -363,7 +369,10 @@
                                            " (min: ", expects[i].min, ", max: 
", expects[i].max, ")");
                                }
                        }
-                       setverdict(fail, "Timeout waiting for metrics");
+                       if (abort_on_failure) {
+                               Misc_Helpers.f_shutdown(__BFILE__, __LINE__, 
fail,
+                                                       log2str("Timeout 
waiting for expect=", expects, " matched=", matched));
+                       }
                        return false;
                }
                }
@@ -381,7 +390,10 @@
                                }
                                log("Metric: ", metric);
                                log("Expect: ", expects[res.idx]);
-                               setverdict(fail, "Metric failed expectation ", 
metric, " vs ", expects[res.idx]);
+                               if (abort_on_failure) {
+                                       Misc_Helpers.f_shutdown(__BFILE__, 
__LINE__, fail,
+                                                               log2str("Metric 
failed expectation ", metric, " vs ", expects[res.idx]));
+                               }
                                return false;
                        }
                        if (res.kind == e_Matched) {
@@ -441,20 +453,20 @@
        return snapshot;
 }

-function f_statsd_expect(StatsDExpects expects, boolean wait_converge := 
false) runs on StatsD_ConnHdlr return boolean {
+function f_statsd_expect(StatsDExpects expects, boolean wait_converge := 
false, boolean abort_on_failure := true) runs on StatsD_ConnHdlr return boolean 
{
        var boolean res;

        if (not mp_enable_stats) {
                return true;
        }

-       STATSD_PROC.call(STATSD_expect:{expects, wait_converge, false, {}}) {
-               [] STATSD_PROC.getreply(STATSD_expect:{expects, wait_converge, 
false, {}}) -> value res;
+       STATSD_PROC.call(STATSD_expect:{expects, wait_converge, 
abort_on_failure, false, {}}) {
+               [] STATSD_PROC.getreply(STATSD_expect:{expects, wait_converge, 
abort_on_failure, false, {}}) -> value res;
        }
        return res;
 }

-function f_statsd_expect_from_snapshot(StatsDExpects expects, boolean 
wait_converge := false,
+function f_statsd_expect_from_snapshot(StatsDExpects expects, boolean 
wait_converge := false, boolean abort_on_failure := true,
                                       StatsDMetrics snapshot := {}) runs on 
StatsD_ConnHdlr return boolean {
        var boolean res;

@@ -462,8 +474,8 @@
                return true;
        }

-       STATSD_PROC.call(STATSD_expect:{expects, wait_converge, true, 
snapshot}) {
-               [] STATSD_PROC.getreply(STATSD_expect:{expects, wait_converge, 
true, snapshot}) -> value res;
+       STATSD_PROC.call(STATSD_expect:{expects, wait_converge, 
abort_on_failure, true, snapshot}) {
+               [] STATSD_PROC.getreply(STATSD_expect:{expects, wait_converge, 
abort_on_failure, true, snapshot}) -> value res;
        }
        return res;
 }

--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/41640?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: Ibc3d079c2a45aa22f9e2e42d75109cae66530f86
Gerrit-Change-Number: 41640
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>

Reply via email to