浏览代码

Add test for when unlink fails in clear_autochildlogdir()

Mike Naberezny 10 年之前
父节点
当前提交
42c20aabb1
共有 2 个文件被更改,包括 18 次插入2 次删除
  1. 1 1
      supervisor/options.py
  2. 17 1
      supervisor/tests/test_options.py

+ 1 - 1
supervisor/options.py

@@ -1225,7 +1225,7 @@ class ServerOptions(Options):
             if fnre.match(filename):
                 pathname = os.path.join(childlogdir, filename)
                 try:
-                    os.remove(pathname)
+                    self.remove(pathname)
                 except (OSError, IOError):
                     self.logger.warn('Failed to clean up %r' % pathname)
 

+ 17 - 1
supervisor/tests/test_options.py

@@ -2313,13 +2313,29 @@ class ServerOptionsTests(unittest.TestCase):
         finally:
             shutil.rmtree(dn)
 
-    def test_clear_autochildlog_oserror(self):
+    def test_clear_autochildlogdir_listdir_oserror(self):
         instance = self._makeOne()
         instance.childlogdir = '/tmp/this/cant/possibly/existjjjj'
         instance.logger = DummyLogger()
         instance.clear_autochildlogdir()
         self.assertEqual(instance.logger.data, ['Could not clear childlog dir'])
 
+    def test_clear_autochildlogdir_unlink_oserror(self):
+        dirname = tempfile.mkdtemp()
+        instance = self._makeOne()
+        instance.childlogdir = dirname
+        ident = instance.identifier
+        filename = os.path.join(dirname, 'cat-stdout---%s-ayWAp9.log' % ident)
+        with open(filename, 'w') as f:
+            f.write("log")
+        def raise_oserror(*args):
+            raise OSError(errno.ENOENT)
+        instance.remove = raise_oserror
+        instance.logger = DummyLogger()
+        instance.clear_autochildlogdir()
+        self.assertEqual(instance.logger.data,
+            ["Failed to clean up '%s'" % filename])
+
     def test_openhttpservers_reports_friendly_usage_when_eaddrinuse(self):
         supervisord = DummySupervisor()
         instance = self._makeOne()