Browse Source

[2353] Test BoB.start_msgq() timeout checks

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

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

@@ -1590,6 +1590,40 @@ class TestBossComponents(unittest.TestCase):
         # this is set by ProcessInfo.spawn()
         self.assertEqual(42147, pi.pid)
 
+    def test_start_msgq_timeout(self):
+        '''Test that b10-msgq startup attempts connections several times
+        and times out eventually.'''
+        bob = MockBobSimple()
+        bob.c_channel_env = {}
+        # keep the timeout small for the test to complete quickly
+        bob.msgq_timeout = 1
+
+        # use the MockProcessInfo creator
+        bob._make_process_info = bob._make_mock_process_info
+
+        global attempts
+        attempts = 0
+        tmp_time = time.time
+        def _my_time():
+            global attempts
+            attempts += 1
+            return tmp_time()
+        time.time = _my_time
+
+        thrown = False
+        # An exception will be thrown here when it eventually times out.
+        try:
+            pi = bob.start_msgq()
+        except bind10_src.CChannelConnectError as e:
+            thrown = True
+
+        # We just check that an exception was thrown, and that several
+        # attempts were made to connect.
+        self.assertTrue(thrown)
+        # 1 second of attempts every 0.1 seconds should result in at least 5 attempts, but less than 15
+        self.assertGreater(attempts, 5)
+        self.assertLess(attempts, 15)
+
     def test_start_cfgmgr(self):
         '''Test that b10-cfgmgr is started.'''
         class DummySession():