BIND 10 trac2353, updated. 5450b258dbeaaf876fd35c52a1191e4f083a620e [2353] Use a MockProcessInfo to test BoB.start_process()

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Nov 16 06:21:57 UTC 2012


The branch, trac2353 has been updated
       via  5450b258dbeaaf876fd35c52a1191e4f083a620e (commit)
      from  b1c8e1ce93d760fa32e7b977910faa9ed5fc4c30 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5450b258dbeaaf876fd35c52a1191e4f083a620e
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri Nov 16 11:51:35 2012 +0530

    [2353] Use a MockProcessInfo to test BoB.start_process()

-----------------------------------------------------------------------

Summary of changes:
 src/bin/bind10/bind10_src.py.in        |    5 ++++-
 src/bin/bind10/tests/bind10_test.py.in |   27 ++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/bin/bind10/bind10_src.py.in b/src/bin/bind10/bind10_src.py.in
index 8807393..debf51c 100755
--- a/src/bin/bind10/bind10_src.py.in
+++ b/src/bin/bind10/bind10_src.py.in
@@ -493,6 +493,9 @@ 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
@@ -502,7 +505,7 @@ class BoB:
             The port and address arguments are for log messages only.
         """
         self.log_starting(name, port, address)
-        newproc = ProcessInfo(name, args, c_channel_env)
+        newproc = self._make_process_info(name, args, c_channel_env)
         newproc.spawn()
         self.log_started(newproc.pid)
         return newproc
diff --git a/src/bin/bind10/tests/bind10_test.py.in b/src/bin/bind10/tests/bind10_test.py.in
index c9c2491..1f41a6d 100644
--- a/src/bin/bind10/tests/bind10_test.py.in
+++ b/src/bin/bind10/tests/bind10_test.py.in
@@ -510,6 +510,22 @@ class TestBoB(unittest.TestCase):
         self.assertEqual({'command': ['shutdown', {'pid': 42}]},
                          bob.cc_session.msg)
 
+# Mock class for testing BoB's usage of ProcessInfo
+class MockProcessInfo:
+    def __init__(self, name, args, env={}, dev_null_stdout=False,
+                 dev_null_stderr=False):
+        self.name = name
+        self.args = args
+        self.env = env
+        self.dev_null_stdout = dev_null_stdout
+        self.dev_null_stderr = dev_null_stderr
+        self.process = None
+        self.pid = None
+
+    def spawn(self):
+        # set some pid (only used for testing that it is not None anymore)
+        self.pid = 42147
+
 # Class for testing the BoB without actually starting processes.
 # This is used for testing the start/stop components routines and
 # the BoB commands.
@@ -732,6 +748,9 @@ 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)
+
 class MockBobSimple(BoB):
     def __init__(self):
         BoB.__init__(self)
@@ -1534,11 +1553,17 @@ class TestBossComponents(unittest.TestCase):
     def test_start_process(self):
         '''Test that processes can be started.'''
         bob = MockBob()
+
+        # use the MockProcessInfo creator
+        bob._make_process_info = bob._make_mock_process_info
+
         pi = bob.start_process('Test Process', ['/bin/true'], {})
         self.assertEqual('Test Process', pi.name)
         self.assertEqual(['/bin/true'], pi.args)
         self.assertEqual({}, pi.env)
-        self.assertNotEqual(0, pi.pid)
+
+        # this is set by ProcessInfo.spawn()
+        self.assertEqual(42147, pi.pid)
 
     def test_register_process(self):
         '''Test that processes can be registered with BoB.'''



More information about the bind10-changes mailing list