Skip to content

Fix flaky #partition_count test with wait_until helper - #932

Merged
mensfeld merged 3 commits into
masterfrom
fix/partition-count-flaky-wait-until
Aug 5, 2026
Merged

Fix flaky #partition_count test with wait_until helper#932
mensfeld merged 3 commits into
masterfrom
fix/partition-count-flaky-wait-until

Conversation

@mensfeld

@mensfeld mensfeld commented Aug 5, 2026

Copy link
Copy Markdown
Member

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.

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.
@mensfeld mensfeld self-assigned this Aug 5, 2026
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.
@mensfeld
mensfeld marked this pull request as ready for review August 5, 2026 14:30
@mensfeld
mensfeld merged commit 4509a5f into master Aug 5, 2026
20 checks passed
@mensfeld
mensfeld deleted the fix/partition-count-flaky-wait-until branch August 5, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant