Browse Source

added test case for current log removed in RotatingFileHandlerTests

magnus-lycka 11 years ago
parent
commit
8bca5abb82
1 changed files with 17 additions and 0 deletions
  1. 17 0
      supervisor/tests/test_loggers.py

+ 17 - 0
supervisor/tests/test_loggers.py

@@ -177,6 +177,23 @@ class RotatingFileHandlerTests(FileHandlerTests):
         two = open(self.filename+ '.2','r').read()
         two = open(self.filename+ '.2','r').read()
         self.assertEqual(two, 'a'*12)
         self.assertEqual(two, 'a'*12)
 
 
+    def test_current_logfile_removed(self):
+        handler = self._makeOne(self.filename, maxBytes=6, backupCount=1)
+        record = self._makeLogRecord('a' * 4)
+
+        handler.emit(record) # 4 bytes
+        self.assert_(os.path.exists(self.filename))
+        self.assertFalse(os.path.exists(self.filename + '.1'))
+
+        # Someone removes the active log file! :-(
+        os.unlink(self.filename)
+        self.assertFalse(os.path.exists(self.filename))
+
+        handler.emit(record) # 8 bytes, do rollover
+        self.assert_(os.path.exists(self.filename))
+        self.assertFalse(os.path.exists(self.filename + '.1'))
+
+
 class BoundIOTests(unittest.TestCase):
 class BoundIOTests(unittest.TestCase):
     def _getTargetClass(self):
     def _getTargetClass(self):
         from supervisor.loggers import BoundIO
         from supervisor.loggers import BoundIO