Fix flaky #partition_count test with wait_until helper - #932
Merged
Conversation
The '#partition_count when topic does not exist' test relied on a fixed sleep(1) between triggering the async metadata fetch (which auto-creates the topic) and asserting the partition count. On slower/loaded CI runners the metadata was not always ready within one second, so partition_count returned -1 and the test failed intermittently across the matrix. Add a reusable wait_until helper in test_helper.rb that polls a block until it returns truthy or a timeout expires, and use it to wait for the partition count to settle. This removes the race and also returns as soon as the metadata is available instead of always paying a fixed delay.
Apply the new wait_until helper to other specs that bet on a fixed sleep before asserting on an asynchronously-produced result: - producer_test: signal-trap close (USR1 handler closes on another thread) and the idle-disconnect instrumentation shutdown. - datadog metrics_listener: async acknowledgement metric, error callback (replaces a hand-rolled 20x0.25s poll loop), topic-level gauge buffer, and the emitted-stats sampling (waits until enough 100ms snapshots accumulate rather than assuming 1s of wall-clock yields them, which under-samples on a loaded runner). These wake up as soon as the condition holds and wait longer when the runner is slow, removing the timing races while keeping the deliberate window-sampling semantics intact.
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.
The '#partition_count when topic does not exist' test relied on a fixed sleep(1) between triggering the async metadata fetch (which auto-creates the topic) and asserting the partition count. On slower/loaded CI runners the metadata was not always ready within one second, so partition_count returned -1 and the test failed intermittently across the matrix.
Add a reusable wait_until helper in test_helper.rb that polls a block until it returns truthy or a timeout expires, and use it to wait for the partition count to settle. This removes the race and also returns as soon as the metadata is available instead of always paying a fixed delay.