Browse Source

[2353] Test BoB.startup()

Mukund Sivaraman 12 years ago
parent
commit
bc4926dac2
1 changed files with 36 additions and 0 deletions
  1. 36 0
      src/bin/bind10/tests/bind10_test.py.in

+ 36 - 0
src/bin/bind10/tests/bind10_test.py.in

@@ -1904,6 +1904,42 @@ class TestBossComponents(unittest.TestCase):
         self.assertEqual(len(bob._unix_sockets), 1)
         self.assertEqual(bob._unix_sockets[42][1], b'You')
 
+    def test_startup(self):
+        '''Test that BoB.startup() handles failures properly.'''
+        class MockBobStartup(BoB):
+            def __init__(self, throw):
+                self.throw = throw
+                self.started = False
+                self.killed = False
+                self.msgq_socket_file = None
+                self.curproc = 'myproc'
+                self.runnable = False
+
+            def start_all_components(self):
+                self.started = True
+                if self.throw:
+                    raise Exception('Assume starting components has failed.')
+
+            def kill_started_components(self):
+                self.killed = True
+
+        # All is well case
+        bob = MockBobStartup(False)
+        r = bob.startup()
+        self.assertIsNone(r)
+        self.assertTrue(bob.started)
+        self.assertFalse(bob.killed)
+        self.assertTrue(bob.runnable)
+
+        # Case where starting all components fails
+        bob = MockBobStartup(True)
+        r = bob.startup()
+        # r contains an error message
+        self.assertEqual(r, 'Unable to start myproc: Assume starting components has failed.')
+        self.assertTrue(bob.started)
+        self.assertTrue(bob.killed)
+        self.assertFalse(bob.runnable)
+
 class SocketSrvTest(unittest.TestCase):
     """
     This tests some methods of boss related to the unix domain sockets used