Pārlūkot izejas kodu

Test the close_fd method on the ServerOptions class.

Chris McDonough 18 gadi atpakaļ
vecāks
revīzija
75d698d531
2 mainītis faili ar 12 papildinājumiem un 1 dzēšanām
  1. 1 1
      src/supervisor/options.py
  2. 11 0
      src/supervisor/tests.py

+ 1 - 1
src/supervisor/options.py

@@ -1067,7 +1067,7 @@ class ServerOptions(Options):
     def close_fd(self, fd):
         try:
             os.close(fd)
-        except:
+        except os.error:
             pass
 
     def fork(self):

+ 11 - 0
src/supervisor/tests.py

@@ -277,6 +277,17 @@ exitcodes=0,1,127
         msg = instance.logger.data[0]
         self.failUnless(msg.startswith('could not write pidfile'))
 
+    def test_close_fd(self):
+        instance = self._makeOne()
+        innie, outie = os.pipe()
+        os.read(innie, 0) # we can read it while its open
+        os.write(outie, 'foo') # we can write to it while its open
+        instance.close_fd(innie)
+        self.assertRaises(os.error, os.read, innie, 0)
+        instance.close_fd(outie)
+        self.assertRaises(os.error, os.write, outie, 'foo')
+        
+
 class TestBase(unittest.TestCase):
     def setUp(self):
         pass