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 <[email protected]>
  • Loading branch information
ganmacs committed Mar 26, 2020
1 parent ee0b2ee commit 10f0935
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 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
6 changes: 6 additions & 0 deletions test/test_daemonizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ class DaemonizerTest < ::Test::Unit::TestCase
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 @@ -52,6 +55,7 @@ class DaemonizerTest < ::Test::Unit::TestCase

File.write(not_readable_path, '1')
FileUtils.chmod(0333, 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 @@ -64,6 +68,7 @@ class DaemonizerTest < ::Test::Unit::TestCase

File.write(not_writable_path, '1')
FileUtils.chmod(0555, 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 @@ -77,6 +82,7 @@ class DaemonizerTest < ::Test::Unit::TestCase

FileUtils.mkdir_p(not_writable_dir)
FileUtils.chmod(0555, 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 10f0935

Please sign in to comment.