Skip to content

Commit

Permalink
* test/logger/test_logdevice.rb: Fix tests of logger to make it work on
Browse files Browse the repository at this point in the history
  windows (windows can not remove opened file) [Bug #11702]
  • Loading branch information
sonots committed Nov 17, 2015
1 parent 3d74897 commit e438ac0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions test/logger/test_logdevice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def test_reopen_io_by_file
def test_reopen_file
logdev = d(@filename)
old_dev = logdev.dev
File.unlink(@filename) if File.exist?(@filename) # remove once, then reopen

This comment has been minimized.

Copy link
@sonots

sonots Nov 17, 2015

Author Owner

I wanted to test an use-case of Logger#reopen to reopen @filename when another process such as logrotated removed @filename. But, because the test itself is impossible on Windows (Windows does not allow to remove opened file), I am just testing that old_dev is surely closed by reopen here now.


logdev.reopen
begin
assert(File.exist?(@filename))
Expand All @@ -154,14 +154,20 @@ def test_reopen_file_by_io
def test_reopen_file_by_file
logdev = d(@filename)
old_dev = logdev.dev
File.unlink(@filename) if File.exist?(@filename) # remove once, then reopen
logdev.reopen(@filename)

tempfile2 = Tempfile.new("logger")
tempfile2.close
filename2 = tempfile2.path
File.unlink(filename2)

logdev.reopen(filename2)
begin
assert(File.exist?(@filename))
assert_equal(@filename, logdev.filename)
assert(File.exist?(filename2))
assert_equal(filename2, logdev.filename)
assert(old_dev.closed?)
ensure
logdev.close
tempfile2.close(true)
end
end

Expand Down

0 comments on commit e438ac0

Please sign in to comment.