Skip to content

Commit 854213b

Browse files
daipomWatson1978
andauthored
Backport(v1.16) test_output_as_buffered_retries: fix flaky test (fluent#4877) (fluent#4915)
**Which issue(s) this PR fixes**: Backport fluent#4877 Fixes fluent#4873 **What this PR does / why we need it**: Before invoke `@num_errors_metrics.inc`, the `does retries correctly when #try_write fails` test will be failed if thread will be switched at https://github.com/fluent/fluentd/blob/f34a2531fcfc4e8958f665301d48558de200aa3a/lib/fluent/plugin/output.rb#L1313-L1315 It is easy to reproduce by adding `sleep` just before `@num_errors_metrics.inc`, like: ```diff diff --git a/lib/fluent/plugin/output.rb b/lib/fluent/plugin/output.rb index a987937..d97d8ec6 100644 --- a/lib/fluent/plugin/output.rb +++ b/lib/fluent/plugin/output.rb @@ -1312,6 +1312,7 @@ def check_slow_flush(start) def update_retry_state(chunk_id, using_secondary, error = nil) @retry_mutex.synchronize do + sleep 0.1 @num_errors_metrics.inc chunk_id_hex = dump_unique_id_hex(chunk_id) ``` This patch will wait until `@num_errors_metrics.inc` is invoked. **Docs Changes**: **Release Note**: <!-- Thank you for contributing to Fluentd! Your commits need to follow DCO: https://probot.github.io/apps/dco/ And please provide the following information to help us make the most of your pull request: --> **Which issue(s) this PR fixes**: Fixes # **What this PR does / why we need it**: **Docs Changes**: **Release Note**: Signed-off-by: Shizuo Fujita <fujita@clear-code.com> Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com> Co-authored-by: Shizuo Fujita <fujita@clear-code.com>
1 parent 500ac03 commit 854213b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

test/plugin/test_output_as_buffered_retries.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ def get_log_time(msg, logs)
941941
@i.enqueue_thread_wait
942942

943943
@i.flush_thread_wakeup
944-
waiting(4){ Thread.pass until @i.write_count > 0 }
944+
waiting(4){ Thread.pass until @i.write_count > 0 && @i.num_errors > 0 }
945945
waiting(4) do
946946
state = @i.instance_variable_get(:@output_flush_threads).first
947947
state.thread.status == 'sleep'
@@ -953,7 +953,7 @@ def get_log_time(msg, logs)
953953
now = @i.next_flush_time
954954
Timecop.freeze( now )
955955
@i.flush_thread_wakeup
956-
waiting(4){ Thread.pass until @i.write_count > 1 }
956+
waiting(4){ Thread.pass until @i.write_count > 1 && @i.num_errors > 1 }
957957
waiting(4) do
958958
state = @i.instance_variable_get(:@output_flush_threads).first
959959
state.thread.status == 'sleep'

0 commit comments

Comments
 (0)