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


##########
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:
   The awk program uses `$$2`, which in awk means an *indirect* field reference 
(the field whose number is the value of `$2`). For `traffic_ctl metric get 
<name>` output like `<metric> <value>`, this will typically read `$<value>` 
(empty) and treat it as 0, causing false failures. Use `$2` to read the metric 
value directly.



-- 
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