Conversation
A number of Etre tests verify the server side metrics after performing some operation (create, update, delete, etc.). The existing assertions assume latency will be 0. Usually it is, but occasionaly on the GitHub servers running automated tests on the PR, the latency will be a few milliseconds. This causes the test to fail since the latency metric will have a value that doesn't match the 0 in the assertion. To fix this, I've added a method "fixLatencyMetric". This method finds any latency metrics in the "expect" list and updates the value to match the corresponding metric from the "actual" list. To make sure the latency metric value is not garbage, fixLatencyMetrics also takes a max latency and asserts that the actual latency is between 0 and max. This way we still check the latency metric has some reasonable value, but we won't fail the test if the latency is a few milliseconds instead of 0.
There was a problem hiding this comment.
Pull Request Overview
This PR adds handling for non-zero latency metrics in server-side tests to prevent intermittent failures by adjusting expected values to match actual latency (within a threshold).
- Inserted
fixLatencyMetriccalls before metric assertions across read/write/query tests. - Added the
fixLatencyMetrichelper inquery_test.goto clamp expected latency to actual values with a max check. - Corrected an
assert.Equalargument order inbulk_write_test.go.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| api/single_entity_write_test.go | Added fixLatencyMetric before metric comparisons. |
| api/single_entity_read_test.go | Added fixLatencyMetric before metric comparisons. |
| api/query_test.go | Added fixLatencyMetric calls and implemented the helper. |
| api/bulk_write_test.go | Added fixLatencyMetric calls and fixed assert.Equal order. |
Comments suppressed due to low confidence (2)
api/query_test.go:387
- The helper comment is misleading: it says it replaces the latency metric in the actual metrics with the expected value, but the code actually replaces the expected value with the actual. Please update the comment to accurately describe this behavior.
// fixLatencyMetric is a helper function that fixes the latency metric in the actual metrics. Since latency is non-deterministic, it can cause
api/bulk_write_test.go:637
- Swap the arguments to
assert.Equalso the expected value comes first:assert.Equal(t, expectMetrics, server.metricsrec.Called).
assert.Equal(t, server.metricsrec.Called, expectMetrics)
daniel-nichter
previously approved these changes
Jun 4, 2025
qian-squareup
previously approved these changes
Jun 4, 2025
wen-hui-sun
reviewed
Jun 4, 2025
ec563af
wen-hui-sun
approved these changes
Jun 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A number of Etre tests verify the server side metrics after performing some operation (create, update, delete, etc.). The existing assertions assume latency will be 0. Usually it is, but occasionaly on the GitHub servers running automated tests on the PR, the latency will be a few milliseconds. This causes the test to fail since the latency metric will have a value that doesn't match the 0 in the assertion.
To fix this, I've added a method "fixLatencyMetric". This method finds any latency metrics in the "expect" list and updates the value to match the corresponding metric from the "actual" list. To make sure the latency metric value is not garbage, fixLatencyMetrics also takes a max latency and asserts that the actual latency is between 0 and max. This way we still check the latency metric has some reasonable value, but we won't fail the test if the latency is a few milliseconds instead of 0.