Browse Source

[2353] Test BoB.start_msgq()

Mukund Sivaraman 12 years ago
parent
commit
15249e567c
2 changed files with 57 additions and 9 deletions
  1. 15 7
      src/bin/bind10/bind10_src.py.in
  2. 42 2
      src/bin/bind10/tests/bind10_test.py.in

+ 15 - 7
src/bin/bind10/bind10_src.py.in

@@ -216,6 +216,7 @@ class BoB:
         self.clear_config = clear_config
         self.cmdctl_port = cmdctl_port
         self.wait_time = wait_time
+        self.msgq_timeout = 5
         self._component_configurator = isc.bind10.component.Configurator(self,
             isc.bind10.special_component.get_specials())
         # The priorities here make them start in the correct order. First
@@ -412,21 +413,30 @@ class BoB:
     # raised which is caught by the caller of start_all_processes(); this kills
     # processes started up to that point before terminating the program.
 
+    def _make_process_info(self, name, args, env,
+                           dev_null_stdout=False, dev_null_stderr=False):
+        return ProcessInfo(name, args, env, dev_null_stdout, dev_null_stderr)
+
     def start_msgq(self):
         """
             Start the message queue and connect to the command channel.
         """
         self.log_starting("b10-msgq")
-        msgq_proc = ProcessInfo("b10-msgq", ["b10-msgq"], self.c_channel_env,
-                                True, not self.verbose)
+        msgq_proc = self._make_process_info("b10-msgq", ["b10-msgq"],
+                                            self.c_channel_env,
+                                            True, not self.verbose)
         msgq_proc.spawn()
         self.log_started(msgq_proc.pid)
 
         # Now connect to the c-channel
         cc_connect_start = time.time()
         while self.cc_session is None:
+            # this is only used by unittests
+            if self.msgq_timeout == 0:
+                break
+
             # if we have been trying for "a while" give up
-            if (time.time() - cc_connect_start) > 5:
+            if (time.time() - cc_connect_start) > self.msgq_timeout:
                 raise CChannelConnectError("Unable to connect to c-channel after 5 seconds")
 
             # try to connect, and if we can't wait a short while
@@ -437,7 +447,8 @@ class BoB:
 
         # Subscribe to the message queue.  The only messages we expect to receive
         # on this channel are once relating to process startup.
-        self.cc_session.group_subscribe("Boss")
+        if self.cc_session is not None:
+            self.cc_session.group_subscribe("Boss")
 
         return msgq_proc
 
@@ -493,9 +504,6 @@ class BoB:
 
     # A couple of utility methods for starting processes...
 
-    def _make_process_info(self, name, args, c_channel_env):
-        return ProcessInfo(name, args, c_channel_env)
-
     def start_process(self, name, args, c_channel_env, port=None, address=None):
         """
             Given a set of command arguments, start the process and output

+ 42 - 2
src/bin/bind10/tests/bind10_test.py.in

@@ -748,8 +748,10 @@ class MockBob(BoB):
     def _get_process_exit_status_raises_other(self):
         raise Exception('Mock error')
 
-    def _make_mock_process_info(self, name, args, c_channel_env):
-        return MockProcessInfo(name, args, c_channel_env)
+    def _make_mock_process_info(self, name, args, c_channel_env,
+                                dev_null_stdout=False, dev_null_stderr=False):
+        return MockProcessInfo(name, args, c_channel_env,
+                               dev_null_stdout, dev_null_stderr)
 
 class MockBobSimple(BoB):
     def __init__(self):
@@ -758,6 +760,11 @@ class MockBobSimple(BoB):
         self.started_process_name = None
         self.started_process_args = None
 
+    def _make_mock_process_info(self, name, args, c_channel_env,
+                                dev_null_stdout=False, dev_null_stderr=False):
+        return MockProcessInfo(name, args, c_channel_env,
+                               dev_null_stdout, dev_null_stderr)
+
     def start_process(self, name, args, c_channel_env, port=None, address=None):
         self.started_process_name = name
         self.started_process_args = args
@@ -1550,6 +1557,39 @@ class TestBossComponents(unittest.TestCase):
         self.assertFalse(bob.get_processes())
         self.assertTrue(component.forceful)
 
+    def test_start_msgq(self):
+        '''Test that b10-msgq is started.'''
+        bob = MockBobSimple()
+        bob.c_channel_env = {}
+        bob.msgq_timeout = 0
+
+        # use the MockProcessInfo creator
+        bob._make_process_info = bob._make_mock_process_info
+
+        # non-verbose case
+        bob.verbose = False
+        pi = bob.start_msgq()
+        self.assertEqual('b10-msgq', pi.name)
+        self.assertEqual(['b10-msgq'], pi.args)
+        self.assertTrue(pi.dev_null_stdout)
+        self.assertTrue(pi.dev_null_stderr)
+        self.assertEqual({}, pi.env)
+
+        # this is set by ProcessInfo.spawn()
+        self.assertEqual(42147, pi.pid)
+
+        # verbose case
+        bob.verbose = True
+        pi = bob.start_msgq()
+        self.assertEqual('b10-msgq', pi.name)
+        self.assertEqual(['b10-msgq'], pi.args)
+        self.assertTrue(pi.dev_null_stdout)
+        self.assertFalse(pi.dev_null_stderr)
+        self.assertEqual({}, pi.env)
+
+        # this is set by ProcessInfo.spawn()
+        self.assertEqual(42147, pi.pid)
+
     def test_start_process(self):
         '''Test that processes can be started.'''
         bob = MockBob()