Skip to content

Backport(v1.19): test_in_tail: fix flaky throttling test (#5381)#5386

Merged
Watson1978 merged 1 commit into
v1.19from
backport-to-v1.19/pr5381
Jun 15, 2026
Merged

Backport(v1.19): test_in_tail: fix flaky throttling test (#5381)#5386
Watson1978 merged 1 commit into
v1.19from
backport-to-v1.19/pr5381

Conversation

@github-actions

Copy link
Copy Markdown

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.

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 whileloop. 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

**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 Watson1978 merged commit 100aa40 into v1.19 Jun 15, 2026
18 checks passed
@Watson1978 Watson1978 deleted the backport-to-v1.19/pr5381 branch June 15, 2026 01:05
@Watson1978 Watson1978 added the CI Test/CI issues label Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Test/CI issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant