Skip to content

Commit

Permalink
fix bug to read worker pids
Browse files Browse the repository at this point in the history
  • Loading branch information
tagomoris committed Dec 10, 2016
1 parent 98abeb5 commit 8c51339
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions test/command/test_fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class TestFluentdCommand < ::Test::Unit::TestCase
TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/../tmp/command/fluentd#{ENV['TEST_ENV_NUMBER']}")
WORKER_PID_PATTERN = /starting fluentd worker pid=(\d+) /

setup do
FileUtils.rm_rf(TMP_DIR)
Expand Down Expand Up @@ -73,20 +74,23 @@ def assert_log_matches(cmdline, *pattern_list, timeout: 10)
stdio_buf = ""
begin
execute_command(cmdline) do |pid, stdout|
waiting(timeout) do
while process_exist?(pid) && !matched
readables, _, _ = IO.select([stdout], nil, nil, 1)
next unless readables
buf = readables.first.readpartial(1024)
if buf =~ /starting fluentd worker pid=(\d+) /m
@worker_pids << $1.to_i
end
stdio_buf << buf
lines = stdio_buf.split("\n")
if pattern_list.all?{|ptn| lines.any?{|line| ptn.is_a?(Regexp) ? ptn.match(line) : line.include?(ptn) } }
matched = true
begin
waiting(timeout) do
while process_exist?(pid) && !matched
readables, _, _ = IO.select([stdout], nil, nil, 1)
next unless readables

stdio_buf << readables.first.readpartial(1024)
lines = stdio_buf.split("\n")
if pattern_list.all?{|ptn| lines.any?{|line| ptn.is_a?(Regexp) ? ptn.match(line) : line.include?(ptn) } }
matched = true
end
end
end
ensure
stdio_buf.scan(WORKER_PID_PATTERN) do |worker_pid|
@worker_pids << worker_pid.first.to_i
end
end
end
rescue Timeout::Error
Expand All @@ -105,25 +109,27 @@ def assert_fluentd_fails_to_start(cmdline, *pattern_list, timeout: 10)
stdio_buf = ""
begin
execute_command(cmdline) do |pid, stdout|
waiting(timeout) do
while process_exist?(pid) && !running
readables, _, _ = IO.select([stdout], nil, nil, 1)
next unless readables
next if readables.first.eof?
begin
waiting(timeout) do
while process_exist?(pid) && !running
readables, _, _ = IO.select([stdout], nil, nil, 1)
next unless readables
next if readables.first.eof?

buf = readables.first.readpartial(1024)
if buf =~ /starting fluentd worker pid=(\d+) /m
@worker_pids << $1.to_i
end
stdio_buf << buf
lines = stdio_buf.split("\n")
if lines.any?{|line| line.include?("fluentd worker is now running") }
running = true
end
if pattern_list.all?{|ptn| lines.any?{|line| ptn.is_a?(Regexp) ? ptn.match(line) : line.include?(ptn) } }
matched = true
stdio_buf << readables.first.readpartial(1024)
lines = stdio_buf.split("\n")
if lines.any?{|line| line.include?("fluentd worker is now running") }
running = true
end
if pattern_list.all?{|ptn| lines.any?{|line| ptn.is_a?(Regexp) ? ptn.match(line) : line.include?(ptn) } }
matched = true
end
end
end
ensure
stdio_buf.scan(WORKER_PID_PATTERN) do |worker_pid|
@worker_pids << worker_pid.first.to_i
end
end
end
rescue Timeout::Error
Expand Down

0 comments on commit 8c51339

Please sign in to comment.