Skip to content

Commit a16ca30

Browse files
Backport(v1.19): test_out_exec_filter: fix flaky test on Windows (#5380) (#5387)
**Which issue(s) this PR fixes**: Backport #5380 Fixes # **What this PR does / why we need it**: The `test 'using child processes by round robin'` in `test_out_exec_filter.rb` was occasionally failing on Windows. Like: ``` 3) Failure: test: using child processes by round robin[with sections](ExecFilterOutputTest) D:/a/fluentd/fluentd/test/plugin/test_out_exec_filter.rb:533:in 'block in <class:ExecFilterOutputTest>' 530: 531: assert_equal pid_list[0], events[0][2]['child_pid'] 532: assert_equal pid_list[1], events[1][2]['child_pid'] => 533: assert_equal pid_list[0], events[2][2]['child_pid'] 534: assert_equal pid_list[1], events[3][2]['child_pid'] 535: end 536: <"8944"> expected but was <"2728"> diff: ? 2728944 Error: <"8944"> expected but was <"2728">. ``` The test previously assumed that the events would be processed and returned in a strictly alternating order (e.g., A -> B -> A -> B). However, on Windows, the overhead of process creation and unpredictable I/O scheduling can cause the child processes to become ready and return events out of order (e.g., A -> B -> B -> A), resulting in false-positive test failures. This commit fixes the flaky behavior by verifying the even distribution of events rather than their strict chronological return order. **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> Co-authored-by: Shizuo Fujita <fujita@clear-code.com>
1 parent 100aa40 commit a16ca30

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

test/plugin/test_out_exec_filter.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -521,17 +521,10 @@ def create_driver(conf)
521521
events = d.events
522522
assert_equal 4, events.length
523523

524-
pid_list = []
525-
events.each do |event|
526-
pid = event[2]['child_pid']
527-
pid_list << pid unless pid_list.include?(pid)
528-
end
529-
assert_equal 2, pid_list.size, "the number of pids should be same with number of child processes: #{pid_list.inspect}"
524+
pid_counts = events.map { |event| event[2]['child_pid'] }.tally
530525

531-
assert_equal pid_list[0], events[0][2]['child_pid']
532-
assert_equal pid_list[1], events[1][2]['child_pid']
533-
assert_equal pid_list[0], events[2][2]['child_pid']
534-
assert_equal pid_list[1], events[3][2]['child_pid']
526+
assert_equal 2, pid_counts.size, "the number of pids should be same with number of child processes: #{pid_counts.inspect}"
527+
assert_equal [2, 2], pid_counts.values, "each child process should handle exactly 2 events"
535528
end
536529

537530
# child process exits per 3 lines

0 commit comments

Comments
 (0)