fix(test): Make jitter deterministic via config override in the flusher test - #69264
Merged
Conversation
Add a #[cfg(test)] jitter_override field to BillingAggregatorConfig so the flusher timing test can pin jitter to a known value (100ms), eliminating the non-deterministic timing race caused by rand::thread_rng() in pick_jitter(). The test_flusher_swallows_initial_tick_then_flushes_on_interval test was flaky (~21 failures over 36 days) because random jitter made the interval creation time unpredictable under paused tokio time.
The field needs to exist in non-test builds too since clippy runs with --all-targets (which enables cfg(test)) and config.rs constructs the struct outside of #[cfg(test)] modules. The field is #[doc(hidden)] and defaults to None with zero runtime cost.
…in mapping test - fix off-by-one-ms timing comments in test_flusher_swallows_initial_tick_then_flushes_on_interval (t=1101ms, not t=1100ms) - clarify the jitter is pinned, not a random range, in this test - assert jitter_override stays None in get_billing_aggregator_config_maps_fields_correctly
|
stamphog does not review bot-authored PRs — removing the |
haacked
enabled auto-merge (squash)
July 9, 2026 19:28
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.
Summary
#[cfg(test)]jitter_overridefield toBillingAggregatorConfigsotest_flusher_swallows_initial_tick_then_flushes_on_intervalcan pin jitter to a known value (100ms), eliminating the non-deterministic timing racepick_jitterusesrand::thread_rng(), making the interval creation time unpredictable under paused tokio timeHow it works
With
jitter_override: Some(Duration::from_millis(100)), the flusher sleeps for exactly 100ms. Afteradvance(101ms), it wakes and creates the interval at t≈100ms. The first real tick fires at t=1100ms. The test advances to t=1099ms and asserts zero flushes — this now passes deterministically regardless of RNG state.Insight
https://app.mendral.com/insights/01KT4HT5VY3AR9V53KRG28G9N4
Note
Created by Mendral. Tag @mendral-app with feedback or questions.