-
Notifications
You must be signed in to change notification settings - Fork 474
exporter: fix flaky Test_rateLimitExport with polling #4280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Replace fixed sleep with polling-based synchronization to eliminate timing-dependent race condition that caused intermittent test failures. The test was using a fixed 200ms sleep which created a window where multiple ticker intervals could fire, causing off-by-one errors in event counts. The new approach polls every 10ms until expected events are received, with a 500ms timeout for robustness. Fixes cilium#2789 Signed-off-by: Farooq Shaikh <[email protected]>
299f80b to
57d5e47
Compare
|
This PR fixes a flaky test with no user-facing changes. Could a maintainer please add the |
FedeDP
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
mtardy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm as well, only a few golang nits. Will merge this later, give you some time to update the patch or not depending on what you prefer! thanks
| func countEvents(eventsJSON []string) (int, int, uint64) { | ||
| gotEvents, gotRateLimitInfo, gotDropped := 0, 0, uint64(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd used the named return parameters feature if you are anyway going to do it
| func countEvents(eventsJSON []string) (int, int, uint64) { | |
| gotEvents, gotRateLimitInfo, gotDropped := 0, 0, uint64(0) | |
| func countEvents(eventsJSON []string) (gotEvents int, gotRateLimitInfo int, gotDropped uint64) { |
| pollLoop: | ||
| for { | ||
| gotEvents, gotRateLimitInfo, _ := countEvents(results.items) | ||
| if gotEvents >= tt.wantEvents && gotRateLimitInfo >= tt.wantRateLimitInfo { | ||
| // We have all the expected output, proceed to cleanup and assertions. | ||
| break pollLoop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to name it in your case?
| pollLoop: | |
| for { | |
| gotEvents, gotRateLimitInfo, _ := countEvents(results.items) | |
| if gotEvents >= tt.wantEvents && gotRateLimitInfo >= tt.wantRateLimitInfo { | |
| // We have all the expected output, proceed to cleanup and assertions. | |
| break pollLoop | |
| for { | |
| gotEvents, gotRateLimitInfo, _ := countEvents(results.items) | |
| if gotEvents >= tt.wantEvents && gotRateLimitInfo >= tt.wantRateLimitInfo { | |
| // We have all the expected output, proceed to cleanup and assertions. | |
| break |
Summary
This PR fixes the flaky Test_rateLimitExport test by replacing the fixed sleep duration with a polling-based synchronization mechanism, addressing the timing race condition reported in #2789.
Related Issue
Fixes #2789
Root Cause
The test used a fixed 200ms sleep which allowed multiple rate limiter ticker intervals (50ms each) to fire during the wait period. This created a timing window where:
Proposed Changes
Testing Performed
Backward Compatibility
No breaking changes. The fix only modifies the test implementation, not the rate limiter functionality itself.
Changelog