Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_child_process: Try to fix unstable tests #3787

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions test/plugin_helper/test_child_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,28 +321,40 @@ def configure(conf)
ary = []
arguments = ["okay"]
Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
start_time = Fluent::Clock.now
@d.child_process_execute(:t5, "echo", arguments: arguments, interval: 1, mode: [:read]) do |io|
ary << io.read.split("\n").map(&:chomp).join
end
sleep 2.9 # 2sec(second invocation) + 0.9sec
1.upto(2) do |i|
sleep 0.1 while ary.size < i
elapsed = Fluent::Clock.now - start_time
assert_equal(i, ary.size)
assert_true(elapsed > i && elapsed < i + 0.5,
"actual elapsed: #{elapsed}")
end
assert_equal [], @d.log.out.logs
@d.stop
assert_equal [], @d.log.out.logs
@d.shutdown; @d.close; @d.terminate
assert_equal 2, ary.size
end
end

test 'can execute external command many times, with leading once executed immediately' do
ary = []
arguments = ["okay"]
Timeout.timeout(TEST_DEADLOCK_TIMEOUT) do
start_time = Fluent::Clock.now
@d.child_process_execute(:t6, "echo", arguments: arguments, interval: 1, immediate: true, mode: [:read]) do |io|
ary << io.read.split("\n").map(&:chomp).join
end
sleep 1.9 # 1sec(second invocation) + 0.9sec
0.upto(1) do |i|
sleep 0.1 while ary.size < i + 1
elapsed = Fluent::Clock.now - start_time
assert_equal(i + 1, ary.size)
assert_true(elapsed > i && elapsed < i + 0.5,
"actual elapsed: #{elapsed}")
end
@d.stop; @d.shutdown; @d.close; @d.terminate
assert_equal 2, ary.size
assert_equal [], @d.log.out.logs
end
end
Expand Down