diff options
author | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-08-20 13:43:46 +0000 |
---|---|---|
committer | nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-08-20 13:43:46 +0000 |
commit | d17031f41a3deaf2bb1e9855a7f76521a974409d (patch) | |
tree | c4a9c2ac27b86d2fee1a18f7fda16d41115d9cb3 /test/logger | |
parent | 4c0f3df36c2fe724f6f62430d9b8bdc25fa66c3f (diff) |
* lib/logger.rb (write, shift_log?, shift_log): file shifting race
condition bug fixed. [ruby-dev:26764]
* test/logger/test_logger.rb: tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9011 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/logger')
-rw-r--r-- | test/logger/test_logger.rb | 78 |
1 files changed, 70 insertions, 8 deletions
diff --git a/test/logger/test_logger.rb b/test/logger/test_logger.rb index c953a89d9c..3528ff21e2 100644 --- a/test/logger/test_logger.rb +++ b/test/logger/test_logger.rb @@ -90,15 +90,9 @@ class TestLogger < Test::Unit::TestCase logger = Logger.new(dummy) log = log_add(logger, INFO, "foo") assert_match(/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\s*\d+ $/, log.datetime) - # [ruby-dev:24828] - #logger.datetime_format = "%d%b%Y@%H:%M:%S" - #log = log_add(logger, INFO, "foo") - #assert_match(/^\d\d\w\w\w\d\d\d\d@\d\d:\d\d:\d\d$/, log.datetime) - # - # don't run the next test at 23:59, or just run again if failed. - logger.datetime_format = "@%d%b%Y@" + logger.datetime_format = "%d%b%Y@%H:%M:%S" log = log_add(logger, INFO, "foo") - assert_equal(Time.now.strftime("@%d%b%Y@"), log.datetime) + assert_match(/^\d\d\w\w\w\d\d\d\d@\d\d:\d\d:\d\d$/, log.datetime) logger.datetime_format = "" log = log_add(logger, INFO, "foo") assert_match(/^$/, log.datetime) @@ -279,4 +273,72 @@ class TestLogDevice < Test::Unit::TestCase assert(w.closed?) r.close end + + def test_shifting_size + logfile = File.basename(__FILE__) + '_1.log' + logfile0 = logfile + '.0' + logfile1 = logfile + '.1' + logfile2 = logfile + '.2' + logfile3 = logfile + '.3' + File.unlink(logfile) if File.exist?(logfile) + File.unlink(logfile0) if File.exist?(logfile0) + File.unlink(logfile1) if File.exist?(logfile1) + File.unlink(logfile2) if File.exist?(logfile2) + logger = Logger.new(logfile, 4, 100) + logger.error("0" * 15) + assert(File.exist?(logfile)) + assert(!File.exist?(logfile0)) + logger.error("0" * 15) + assert(File.exist?(logfile0)) + assert(!File.exist?(logfile1)) + logger.error("0" * 15) + assert(File.exist?(logfile1)) + assert(!File.exist?(logfile2)) + logger.error("0" * 15) + assert(File.exist?(logfile2)) + assert(!File.exist?(logfile3)) + logger.error("0" * 15) + assert(!File.exist?(logfile3)) + logger.error("0" * 15) + assert(!File.exist?(logfile3)) + File.unlink(logfile) + File.unlink(logfile0) + File.unlink(logfile1) + File.unlink(logfile2) + + logfile = File.basename(__FILE__) + '_2.log' + logfile0 = logfile + '.0' + logfile1 = logfile + '.1' + logfile2 = logfile + '.2' + logfile3 = logfile + '.3' + logger = Logger.new(logfile, 4, 150) + logger.error("0" * 15) + assert(File.exist?(logfile)) + assert(!File.exist?(logfile0)) + logger.error("0" * 15) + assert(!File.exist?(logfile0)) + logger.error("0" * 15) + assert(File.exist?(logfile0)) + assert(!File.exist?(logfile1)) + logger.error("0" * 15) + assert(!File.exist?(logfile1)) + logger.error("0" * 15) + assert(File.exist?(logfile1)) + assert(!File.exist?(logfile2)) + logger.error("0" * 15) + assert(!File.exist?(logfile2)) + logger.error("0" * 15) + assert(File.exist?(logfile2)) + assert(!File.exist?(logfile3)) + logger.error("0" * 15) + assert(!File.exist?(logfile3)) + logger.error("0" * 15) + assert(!File.exist?(logfile3)) + logger.error("0" * 15) + assert(!File.exist?(logfile3)) + File.unlink(logfile) + File.unlink(logfile0) + File.unlink(logfile1) + File.unlink(logfile2) + end end |