Backport(v1.19): test_in_tail: fix flaky throttling test (#5381)#5386
Merged
Conversation
**Which issue(s) this PR fixes**:
Fixes #
**What this PR does / why we need it**:
The `test "lines collected with throttling"` was intermittently failing,
especially on macOS CI runners.
```
4) Failure: test: lines collected with throttling(TailInputTest::throttling logs at in_tail level):
elapsed_seconds 1.81999524999992 is out of allowed range:
lower: 1.88 [sec]
upper: 3.3200000000000003 [sec].
<true> expected but was
<false>
/Users/runner/work/fluentd/fluentd/test/plugin/test_in_tail.rb:2793:in 'block (3 levels) in <class:TailInputTest>'
2790: sleep(sleep_interval) while d.emit_count <= emit_count
2791: elapsed_seconds = Fluent::Clock.now - start_time
2792: if emit_count > 0
=> 2793: assert_true(elapsed_seconds > lower_interval && elapsed_seconds < upper_interval,
2794: "elapsed_seconds #{elapsed_seconds} is out of allowed range:\n" +
2795: " lower: #{lower_interval} [sec]\n" +
2796: " upper: #{upper_interval} [sec]")
```
The failure occurred because the test was measuring the test thread's
observation delay rather than the actual interval between emit events.
Previously, `start_time` was recorded at the beginning of the
`while`loop. If the OS thread scheduling was delayed, the time spent
waiting was excluded from the current cycle and bled into the next,
causing `elapsed_seconds` to falsely fall below the `lower_interval`
threshold.
By moving `start_time = Fluent::Clock.now` outside the loop and updating
it immediately after confirming an emit, we accurately measure the
duration between consecutive emits. This makes the test resilient to CI
scheduling jitter.
**Docs Changes**:
N/A
**Release Note**:
N/A
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Watson1978
approved these changes
Jun 15, 2026
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.
Which issue(s) this PR fixes:
Backport #5381
Fixes #
What this PR does / why we need it:
The
test "lines collected with throttling"was intermittently failing, especially on macOS CI runners.The failure occurred because the test was measuring the test thread's observation delay rather than the actual interval between emit events.
Previously,
start_timewas recorded at the beginning of thewhileloop. If the OS thread scheduling was delayed, the time spent waiting was excluded from the current cycle and bled into the next, causingelapsed_secondsto falsely fall below thelower_intervalthreshold.By moving
start_time = Fluent::Clock.nowoutside the loop and updating it immediately after confirming an emit, we accurately measure the duration between consecutive emits. This makes the test resilient to CI scheduling jitter.Docs Changes:
N/A
Release Note:
N/A