From: Mukund Sivaraman Date: Fri, 16 Nov 2012 05:27:35 +0000 (+0530) Subject: [2353] Test exception handling in BoB.reap_children() X-Git-Tag: bind10-1.0.0-beta-release~19^2~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09f21f49fa1e214af117262c305efb3968becd8f;p=thirdparty%2Fkea.git [2353] Test exception handling in BoB.reap_children() --- diff --git a/src/bin/bind10/tests/bind10_test.py.in b/src/bin/bind10/tests/bind10_test.py.in index debf0cf2a4..836e1f9b72 100644 --- a/src/bin/bind10/tests/bind10_test.py.in +++ b/src/bin/bind10/tests/bind10_test.py.in @@ -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()