@@ -384,9 +384,10 @@ func TestResponseCompression(t *testing.T) {
384
384
assert .Equal (t , "application/json" , res .Header .Get ("Content-Type" ))
385
385
}
386
386
387
- // fixLatencyMetric is a helper function that fixes the latency metric in the actual metrics. Since latency is non-deterministic, it can cause
388
- // tests to fail. This function replaces the latency metric in the actual metrics with the expected value, so that the test can pass.
389
- // It also asserts that the actual latency is less than the max value, to ensure that the latency is within acceptable limits.
387
+ // fixLatencyMetric is a helper function that fixes the non-deterministic latency to ensure actual==expected for assertions.
388
+ // Since latency is non-deterministic, it can cause tests to fail intermittently. This function replaces the latency metric
389
+ // in the "expect" metrics with the "actual" value, so that the test can pass.
390
+ // It also asserts that the actual latency is between 0 and the provided max value, to ensure that the latency is within acceptable limits.
390
391
func fixLatencyMetric (t * testing.T , max int , expect , actual []mock.MetricMethodArgs ) {
391
392
t .Helper ()
392
393
if len (actual ) != len (expect ) {
@@ -395,7 +396,6 @@ func fixLatencyMetric(t *testing.T, max int, expect, actual []mock.MetricMethodA
395
396
}
396
397
for i , _ := range actual {
397
398
if actual [i ].Metric == metrics .LatencyMs && expect [i ].Metric == metrics .LatencyMs && actual [i ].Method == expect [i ].Method {
398
- // Replace the latency metric with the expected value.
399
399
assert .True (t , actual [i ].IntVal >= 0 && actual [i ].IntVal <= int64 (max ), "Latency metric value %d must be between 0 and %d." , actual [i ].IntVal , max )
400
400
expect [i ].IntVal = actual [i ].IntVal
401
401
}
0 commit comments