Skip to content

Commit

Permalink
failing test for log rotation on file referred by multiple handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Whit Morriss committed Dec 15, 2011
1 parent 0e53f90 commit aabd376
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions supervisor/tests/test_loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def test_emit_error(self):
dummy_stderr.written)

class RotatingFileHandlerTests(FileHandlerTests):

def _getTargetClass(self):
from supervisor.loggers import RotatingFileHandler
return RotatingFileHandler
Expand All @@ -134,6 +135,41 @@ def test_ctor(self):
self.assertEqual(handler.maxBytes, 512*1024*1024)
self.assertEqual(handler.backupCount, 10)

def test_emit_tracks_correct_file_for_multiple_handlers(self):
"""
Rollovers should roll for all handlers of the same file.
When more than one process logs to a singlefile, we want to
make sure that files get rotated properly.
When the file rotates, all handlers should start writing to
the file specified by handler.baseFilename.
"""
handler1 = self._makeOne(self.filename, maxBytes=10, backupCount=2)
handler2 = self._makeOne(self.filename, maxBytes=10, backupCount=2)
record = self._makeLogRecord('a' * 4)
handler1.emit(record) #4 bytes
handler2.emit(record) #8 bytes
self.assertFalse(os.path.exists(self.filename + '.1'))
handler1.emit(record) #12 bytes
self.assertTrue(os.path.exists(self.filename + '.1'))
self.assertTrue(handler1.stream == handler2.stream)
new_record = self._makeLogRecord("NEW")
handler2.emit(new_record)
self.assertTrue(open(self.filename).read().endswith("NEW"))
handler1.emit(record)
self.assertTrue(open(self.filename).read().endswith("aaaa"))
handler2.emit(new_record)
self.assertTrue(open(self.filename).read().endswith(""))

## def test_reopen_raises(self):
## handler = self._makeOne(self.filename)
## stream = DummyStream()
## handler.baseFilename = os.path.join(self.basedir, 'notthere', 'a.log')
## handler.open_streams[handler.baseFilename] = stream
## self.assertRaises(IOError, handler.reopen)
## self.assertEqual(stream.closed, True)

def test_emit_does_rollover(self):
handler = self._makeOne(self.filename, maxBytes=10, backupCount=2)
record = self._makeLogRecord('a' * 4)
Expand Down

0 comments on commit aabd376

Please sign in to comment.