logger.rb: fix r43511 for Windows
* lib/logger.rb (Logger::LogDevice::LogDeviceMutex#lock_shift_log): open file can't be removed or renamed on Windows. [ruby-dev:47790] [Bug #9046] * test/logger/test_logger.rb (TestLogDevice#run_children): don't use fork. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
059c94d4f5
commit
3c8072937c
@ -1,3 +1,12 @@
|
|||||||
|
Sat Nov 2 15:14:33 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/logger.rb (Logger::LogDevice::LogDeviceMutex#lock_shift_log):
|
||||||
|
open file can't be removed or renamed on Windows. [ruby-dev:47790]
|
||||||
|
[Bug #9046]
|
||||||
|
|
||||||
|
* test/logger/test_logger.rb (TestLogDevice#run_children): don't use
|
||||||
|
fork.
|
||||||
|
|
||||||
Sat Nov 2 07:08:43 2013 NARUSE, Yui <naruse@ruby-lang.org>
|
Sat Nov 2 07:08:43 2013 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* lib/logger.rb: Inter-process locking for log rotation
|
* lib/logger.rb: Inter-process locking for log rotation
|
||||||
|
@ -633,8 +633,12 @@ private
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if /mswin|mingw/ =~ RUBY_PLATFORM
|
||||||
|
def lock_shift_log
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
else
|
||||||
def lock_shift_log
|
def lock_shift_log
|
||||||
begin
|
|
||||||
retry_limit = 8
|
retry_limit = 8
|
||||||
retry_sleep = 0.1
|
retry_sleep = 0.1
|
||||||
begin
|
begin
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'logger'
|
require 'logger'
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
|
require_relative '../ruby/envutil'
|
||||||
|
|
||||||
|
|
||||||
class TestLoggerSeverity < Test::Unit::TestCase
|
class TestLoggerSeverity < Test::Unit::TestCase
|
||||||
@ -486,30 +487,16 @@ class TestLogDevice < Test::Unit::TestCase
|
|||||||
File.unlink(logfile1) if File.exist?(logfile1)
|
File.unlink(logfile1) if File.exist?(logfile1)
|
||||||
File.unlink(logfile2) if File.exist?(logfile2)
|
File.unlink(logfile2) if File.exist?(logfile2)
|
||||||
begin
|
begin
|
||||||
logger = Logger.new(logfile, 4, 10)
|
stderr = run_children(2, [logfile], <<-'END')
|
||||||
r, w = IO.pipe
|
logger = Logger.new(ARGV[0], 4, 10)
|
||||||
$stderr = w # To capture #warn output in Logger
|
|
||||||
pid1 = Process.fork do
|
|
||||||
10.times do
|
10.times do
|
||||||
logger.info '0' * 15
|
logger.info '0' * 15
|
||||||
end
|
end
|
||||||
end
|
END
|
||||||
pid2 = Process.fork do
|
|
||||||
10.times do
|
|
||||||
logger.info '0' * 15
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Process.waitpid pid1
|
|
||||||
Process.waitpid pid2
|
|
||||||
w.close
|
|
||||||
stderr = r.read
|
|
||||||
r.close
|
|
||||||
assert_no_match(/log shifting failed/, stderr)
|
assert_no_match(/log shifting failed/, stderr)
|
||||||
assert_no_match(/log writing failed/, stderr)
|
assert_no_match(/log writing failed/, stderr)
|
||||||
assert_no_match(/log rotation inter-process lock failed/, stderr)
|
assert_no_match(/log rotation inter-process lock failed/, stderr)
|
||||||
ensure
|
ensure
|
||||||
$stderr = STDERR # restore
|
|
||||||
logger.close if logger
|
|
||||||
File.unlink(logfile) if File.exist?(logfile)
|
File.unlink(logfile) if File.exist?(logfile)
|
||||||
File.unlink(logfile0) if File.exist?(logfile0)
|
File.unlink(logfile0) if File.exist?(logfile0)
|
||||||
File.unlink(logfile1) if File.exist?(logfile1)
|
File.unlink(logfile1) if File.exist?(logfile1)
|
||||||
@ -523,30 +510,16 @@ class TestLogDevice < Test::Unit::TestCase
|
|||||||
filename2 = @filename + ".#{yyyymmdd}.1"
|
filename2 = @filename + ".#{yyyymmdd}.1"
|
||||||
filename3 = @filename + ".#{yyyymmdd}.2"
|
filename3 = @filename + ".#{yyyymmdd}.2"
|
||||||
begin
|
begin
|
||||||
logger = Logger.new(@filename, 'now')
|
stderr = run_children(2, [@filename], <<-'END')
|
||||||
r, w = IO.pipe
|
logger = Logger.new(ARGV[0], 'now')
|
||||||
$stderr = w # To capture #warn output in Logger
|
|
||||||
pid1 = Process.fork do
|
|
||||||
10.times do
|
10.times do
|
||||||
logger.info '0' * 15
|
logger.info '0' * 15
|
||||||
end
|
end
|
||||||
end
|
END
|
||||||
pid2 = Process.fork do
|
|
||||||
10.times do
|
|
||||||
logger.info '0' * 15
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Process.waitpid pid1
|
|
||||||
Process.waitpid pid2
|
|
||||||
w.close
|
|
||||||
stderr = r.read
|
|
||||||
r.close
|
|
||||||
assert_no_match(/log shifting failed/, stderr)
|
assert_no_match(/log shifting failed/, stderr)
|
||||||
assert_no_match(/log writing failed/, stderr)
|
assert_no_match(/log writing failed/, stderr)
|
||||||
assert_no_match(/log rotation inter-process lock failed/, stderr)
|
assert_no_match(/log rotation inter-process lock failed/, stderr)
|
||||||
ensure
|
ensure
|
||||||
$stderr = STDERR # restore
|
|
||||||
logger.close if logger
|
|
||||||
[filename1, filename2, filename3].each do |filename|
|
[filename1, filename2, filename3].each do |filename|
|
||||||
File.unlink(filename) if File.exist?(filename)
|
File.unlink(filename) if File.exist?(filename)
|
||||||
end
|
end
|
||||||
@ -557,26 +530,34 @@ class TestLogDevice < Test::Unit::TestCase
|
|||||||
tmpfile = Tempfile.new([File.basename(__FILE__, '.*'), '_1.log'])
|
tmpfile = Tempfile.new([File.basename(__FILE__, '.*'), '_1.log'])
|
||||||
logfile = tmpfile.path
|
logfile = tmpfile.path
|
||||||
tmpfile.close(true)
|
tmpfile.close(true)
|
||||||
logdev = Logger::LogDevice.new(logfile)
|
|
||||||
File.unlink(logfile) if File.exist?(logfile)
|
|
||||||
begin
|
begin
|
||||||
20.times do
|
20.times do
|
||||||
pid1 = Process.fork do
|
run_children(2, [logfile], <<-'END')
|
||||||
|
logfile = ARGV[0]
|
||||||
|
logdev = Logger::LogDevice.new(logfile)
|
||||||
logdev.send(:open_logfile, logfile)
|
logdev.send(:open_logfile, logfile)
|
||||||
end
|
END
|
||||||
pid2 = Process.fork do
|
assert_equal(1, File.readlines(logfile).grep(/# Logfile created on/).size)
|
||||||
logdev.send(:open_logfile, logfile)
|
|
||||||
end
|
|
||||||
Process.waitpid pid1
|
|
||||||
Process.waitpid pid2
|
|
||||||
assert_not_equal(2, File.readlines(logfile).grep(/# Logfile created on/).size)
|
|
||||||
File.unlink(logfile)
|
File.unlink(logfile)
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
logdev.close if logdev
|
|
||||||
File.unlink(logfile) if File.exist?(logfile)
|
File.unlink(logfile) if File.exist?(logfile)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def run_children(n, args, src)
|
||||||
|
r, w = IO.pipe
|
||||||
|
[w, *(1..n).map do
|
||||||
|
f = IO.popen([EnvUtil.rubybin, *%w[--disable=gems -rlogger -], *args], "w", err: w)
|
||||||
|
f.puts(src)
|
||||||
|
f
|
||||||
|
end].each(&:close)
|
||||||
|
stderr = r.read
|
||||||
|
r.close
|
||||||
|
stderr
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user