Skip to content

Commit

Permalink
need wait for windows and arm arch env?
Browse files Browse the repository at this point in the history
Signed-off-by: Yuta Iwama <ganmacs@gmail.com>
  • Loading branch information
ganmacs committed Mar 26, 2020
1 parent ee0b2ee commit e45c634
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Rake::TestTask.new(:base_test) do |t|
t.test_files = if ENV["WIN_RAPID"]
["test/test_event.rb", "test/test_supervisor.rb", "test/plugin_helper/test_event_loop.rb"]
else
tests = Dir["test/**/test_*.rb"].sort
# tests = Dir["test/**/test_*.rb"].sort
tests = Dir["test/test_daemonizer.rb"].sort
if Process.uid.zero?
puts "test_file_util.rb for non-root user env. Disable this test on root environment"
tests.delete("test/plugin/test_file_util.rb")
Expand Down
11 changes: 10 additions & 1 deletion lib/fluent/daemonizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
# limitations under the License.
#

require 'fluent/config/error'
require 'fluent/plugin/file_util'
# if Fluent.windows?
# require_relative 'file_wrapper'
# else
# Fluent::FileWrapper = File
# end

module Fluent
class Daemonizer
Expand Down Expand Up @@ -52,6 +57,10 @@ def daemonize_with_spawn(pid_fullpath, args)

def check_pidfile(pid_path)
if File.exist?(pid_path)
puts nil, '<============================================================ OUTPUT START HERE'
p Process.uid.nonzero?
p readable: File.readable?(pid_path), writable: File.writable?(pid_path)
puts '<============================================================ OUTPUT CLOSE HERE', nil
if !File.readable?(pid_path) || !File.writable?(pid_path)
raise Fluent::ConfigError, "Cannot access pid file: #{pid_path}"
end
Expand Down
16 changes: 13 additions & 3 deletions test/test_daemonizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ class DaemonizerTest < ::Test::Unit::TestCase

sub_test_case 'when pid file already exists' do
test 'raise an error when process is running' do
omit "root user" if Process.uid.zero?
pid_path = File.join(TMP_DIR, 'file.pid')
File.write(pid_path, '1')

waiting(10) { sleep 0.1 until File.exist?(pid_path) }

mock(Process).daemon(anything, anything).never
mock(Process).spawn(anything).never
mock(Process).kill(0, 1).once

assert_raise(Fluent::ConfigError.new('pid(1) is running')) do
Expand All @@ -48,10 +52,12 @@ class DaemonizerTest < ::Test::Unit::TestCase
end

test 'raise an error when file is not redable' do
omit "root user" if Process.uid.zero?
not_readable_path = File.join(TMP_DIR, 'not_readable.pid')

File.write(not_readable_path, '1')
FileUtils.chmod(0333, not_readable_path)
FileUtils.chmod('-r', not_readable_path)
waiting(10) { sleep 0.1 until (File.exist?(not_readable_path) && !File.readable?(not_readable_path)) }

mock(Process).daemon(anything, anything).never
assert_raise(Fluent::ConfigError.new("Cannot access pid file: #{File.absolute_path(not_readable_path)}")) do
Expand All @@ -60,10 +66,12 @@ class DaemonizerTest < ::Test::Unit::TestCase
end

test 'raise an error when file is not writable' do
omit "root user" if Process.uid.zero?
not_writable_path = File.join(TMP_DIR, 'not_writable.pid')

File.write(not_writable_path, '1')
FileUtils.chmod(0555, not_writable_path)
FileUtils.chmod('-w', not_writable_path)
waiting(10) { sleep 0.1 until (File.exist?(not_writable_path) && !File.writable?(not_writable_path)) }

mock(Process).daemon(anything, anything).never
assert_raise(Fluent::ConfigError.new("Cannot access pid file: #{File.absolute_path(not_writable_path)}")) do
Expand All @@ -72,11 +80,13 @@ class DaemonizerTest < ::Test::Unit::TestCase
end

test 'raise an error when directory is not writable' do
omit "root user" if Process.uid.zero?
not_writable_dir = File.join(TMP_DIR, 'not_writable')
pid_path = File.join(not_writable_dir, 'file.pid')

FileUtils.mkdir_p(not_writable_dir)
FileUtils.chmod(0555, not_writable_dir)
FileUtils.chmod('-w', not_writable_dir)
waiting(10) { sleep 0.1 until !File.writable?(not_writable_dir) }

mock(Process).daemon(anything, anything).never
assert_raise(Fluent::ConfigError.new("Cannot access directory for pid file: #{File.absolute_path(not_writable_dir)}")) do
Expand Down

0 comments on commit e45c634

Please sign in to comment.