]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2353] Test exception handling in BoB.reap_children()
authorMukund Sivaraman <muks@isc.org>
Fri, 16 Nov 2012 05:27:35 +0000 (10:57 +0530)
committerMukund Sivaraman <muks@isc.org>
Fri, 16 Nov 2012 05:27:35 +0000 (10:57 +0530)
src/bin/bind10/tests/bind10_test.py.in

index debf0cf2a41773b58957bbae69a74a7103908a2e..836e1f9b726250afe923110000c3b4c9d82db2c8 100644 (file)
@@ -717,6 +717,15 @@ class MockBob(BoB):
         self.get_process_exit_status_called = True
         return (53, 0)
 
+    def _get_process_exit_status_raises_oserror_echild(self):
+        raise OSError(errno.ECHILD, 'Mock error')
+
+    def _get_process_exit_status_raises_oserror_other(self):
+        raise OSError(0, 'Mock error')
+
+    def _get_process_exit_status_raises_other(self):
+        raise Exception('Mock error')
+
 class MockBobSimple(BoB):
     def __init__(self):
         BoB.__init__(self)
@@ -1448,6 +1457,25 @@ class TestBossComponents(unittest.TestCase):
         # now, we should as the mock component.failed() returns False
         self.assertTrue(component in bob.components_to_restart)
 
+        # case where bob._get_process_exit_status() raises OSError with errno.ECHILD
+        bob._get_process_exit_status = bob._get_process_exit_status_raises_oserror_echild
+        bob.components_to_restart = []
+        # this should catch and handle the OSError
+        bob.reap_children()
+        self.assertFalse(component in bob.components_to_restart)
+
+        # case where bob._get_process_exit_status() raises OSError with
+        # errno other than ECHILD
+        bob._get_process_exit_status = bob._get_process_exit_status_raises_oserror_other
+        with self.assertRaises(OSError):
+            bob.reap_children()
+
+        # case where bob._get_process_exit_status() raises something
+        # other than OSError
+        bob._get_process_exit_status = bob._get_process_exit_status_raises_other
+        with self.assertRaises(Exception):
+            bob.reap_children()
+
     def test_kill_started_components(self):
         '''Test that started components are killed.'''
         bob = MockBob()