moonchen commented on code in PR #13286:
URL: https://github.com/apache/trafficserver/pull/13286#discussion_r3440040223


##########
tests/gold_tests/autest-site/ats_replay.test.ext:
##########
@@ -323,14 +323,28 @@ def ATSReplayTest(obj, replay_file: str):
 
         for check in metric_checks:
             metric_name = check['metric']
-            expected_value = check['value']
-            check_tr = obj.AddTestRun(f'Verify {metric_name} == 
{expected_value}')
-            check_tr.Processes.Default.Command = f'traffic_ctl metric get 
{metric_name}'
-            check_tr.Processes.Default.Env = ts.Env
-            check_tr.Processes.Default.ReturnCode = 0
-            check_tr.Processes.Default.Streams.All = 
Testers.ContainsExpression(
-                f'^{re.escape(metric_name)}\\s+{expected_value}$', 
f'{metric_name} should be {expected_value}')
-            check_tr.StillRunningAfter = ts
+            if 'value' in check:
+                expected_value = check['value']
+                check_tr = obj.AddTestRun(f'Verify {metric_name} == 
{expected_value}')
+                check_tr.Processes.Default.Command = f'traffic_ctl metric get 
{metric_name}'
+                check_tr.Processes.Default.Env = ts.Env
+                check_tr.Processes.Default.ReturnCode = 0
+                check_tr.Processes.Default.Streams.All = 
Testers.ContainsExpression(
+                    f'^{re.escape(metric_name)}\\s+{expected_value}$', 
f'{metric_name} should be {expected_value}')
+                check_tr.StillRunningAfter = ts
+            elif 'min' in check:
+                minimum = check['min']
+                check_tr = obj.AddTestRun(f'Verify {metric_name} >= {minimum}')
+                # Fail if the metric value (field 2) is below the minimum, or 
absent.
+                # $$ escapes the awk field ref from autest's command 
templating.
+                check_tr.Processes.Default.Command = (
+                    f"traffic_ctl metric get {metric_name} | "
+                    f"awk 'BEGIN {{ rc = 1 }} {{ if ($$2 + 0 >= {minimum}) rc 
= 0 }} END {{ exit rc }}'")

Review Comment:
   `$$` here is the escape for autest's command templating (Python 
`Template`-style `$` substitution), so `$$2` reaches awk as `$2` (the second 
field) at run time — as noted in the inline comment on the line above. Writing 
`$2` directly would be consumed by the command templating rather than passed 
through to awk, so the current form is intentional (and the metric check 
passes).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to