BIND 10 trac2353, updated. 02f306c854846cf972886c8f42e1b6e642c89e4a [2353] Unify repeated test code
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Dec 10 01:11:14 UTC 2012
The branch, trac2353 has been updated
via 02f306c854846cf972886c8f42e1b6e642c89e4a (commit)
via 6af3de2d2ee4b43bb5056d8b11cba164ac693346 (commit)
via 366f210b8217811fb1cd96ed996f3491c7d9766f (commit)
from e6ebe1de8e6ab2982869ba27f1719e63fddeb0e3 (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 02f306c854846cf972886c8f42e1b6e642c89e4a
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Dec 10 06:40:41 2012 +0530
[2353] Unify repeated test code
commit 6af3de2d2ee4b43bb5056d8b11cba164ac693346
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Dec 10 06:30:27 2012 +0530
[2353] Use a test environment instead of an empty one
commit 366f210b8217811fb1cd96ed996f3491c7d9766f
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Dec 10 06:14:00 2012 +0530
[2353] Use assertRaises() instead of the excessive code
-----------------------------------------------------------------------
Summary of changes:
src/bin/bind10/tests/bind10_test.py.in | 89 +++++++++++++-------------------
1 file changed, 36 insertions(+), 53 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/bind10/tests/bind10_test.py.in b/src/bin/bind10/tests/bind10_test.py.in
index ac9380e..917e133 100644
--- a/src/bin/bind10/tests/bind10_test.py.in
+++ b/src/bin/bind10/tests/bind10_test.py.in
@@ -1687,6 +1687,26 @@ class TestBossComponents(unittest.TestCase):
# isc.cc.Session, time.time() and time.sleep() are restored
# during tearDown().
+ def _start_cfgmgr_helper(self, bob, data_path, filename, clear_config):
+ expect_args = ['b10-cfgmgr']
+ if data_path is not None:
+ bob.data_path = data_path
+ expect_args.append('--data-path=' + data_path)
+ if filename is not None:
+ bob.config_filename = filename
+ expect_args.append('--config-filename=' + filename)
+ if clear_config:
+ bob.clear_config = clear_config
+ expect_args.append('--clear-config')
+
+ pi = bob.start_cfgmgr()
+ self.assertEqual('b10-cfgmgr', pi.name)
+ self.assertEqual(expect_args, pi.args)
+ self.assertEqual({'TESTENV': 'A test string'}, pi.env)
+
+ # this is set by ProcessInfo.spawn()
+ self.assertEqual(42147, pi.pid)
+
def test_start_cfgmgr(self):
'''Test that b10-cfgmgr is started.'''
class DummySession():
@@ -1701,7 +1721,7 @@ class TestBossComponents(unittest.TestCase):
return ({}, None)
bob = MockBobSimple()
- bob.c_channel_env = {}
+ bob.c_channel_env = {'TESTENV': 'A test string'}
bob.cc_session = DummySession()
bob.wait_time = 5
@@ -1717,56 +1737,24 @@ class TestBossComponents(unittest.TestCase):
time.sleep = _my_sleep
# defaults
- pi = bob.start_cfgmgr()
- self.assertEqual('b10-cfgmgr', pi.name)
- self.assertEqual(['b10-cfgmgr'], pi.args)
- self.assertEqual({}, pi.env)
-
- # this is set by ProcessInfo.spawn()
- self.assertEqual(42147, pi.pid)
+ self._start_cfgmgr_helper(bob, None, None, False)
# check that 2 attempts were made. on the 3rd attempt,
# process_running() returns that ConfigManager is running.
self.assertEqual(attempts, 2)
# data_path is specified
- bob.data_path = '/var/lib/test'
- pi = bob.start_cfgmgr()
- self.assertEqual('b10-cfgmgr', pi.name)
- self.assertEqual(['b10-cfgmgr',
- '--data-path=/var/lib/test'],
- pi.args)
- self.assertEqual({}, pi.env)
-
- # this is set by ProcessInfo.spawn()
- self.assertEqual(42147, pi.pid)
-
- # config_filename is specified
- bob.config_filename = 'foo.cfg'
- pi = bob.start_cfgmgr()
- self.assertEqual('b10-cfgmgr', pi.name)
- self.assertEqual(['b10-cfgmgr',
- '--data-path=/var/lib/test',
- '--config-filename=foo.cfg'],
- pi.args)
- self.assertEqual({}, pi.env)
+ self._start_cfgmgr_helper(bob, '/var/lib/test', None, False)
- # this is set by ProcessInfo.spawn()
- self.assertEqual(42147, pi.pid)
+ # config_filename is specified. Because `bob` is not
+ # reconstructed, data_path is retained from the last call to
+ # _start_cfgmgr_helper().
+ self._start_cfgmgr_helper(bob, '/var/lib/test', 'foo.cfg', False)
- # clear_config is specified
- bob.clear_config = True
- pi = bob.start_cfgmgr()
- self.assertEqual('b10-cfgmgr', pi.name)
- self.assertEqual(['b10-cfgmgr',
- '--data-path=/var/lib/test',
- '--config-filename=foo.cfg',
- '--clear-config'],
- pi.args)
- self.assertEqual({}, pi.env)
-
- # this is set by ProcessInfo.spawn()
- self.assertEqual(42147, pi.pid)
+ # clear_config is specified. Because `bob` is not reconstructed,
+ # data_path and config_filename are retained from the last call
+ # to _start_cfgmgr_helper().
+ self._start_cfgmgr_helper(bob, '/var/lib/test', 'foo.cfg', True)
def test_start_cfgmgr_timeout(self):
'''Test that b10-cfgmgr startup attempts connections several times
@@ -1791,16 +1779,11 @@ class TestBossComponents(unittest.TestCase):
attempts += 1
time.sleep = _my_sleep
- thrown = False
- # An exception will be thrown here when it eventually times out.
- try:
- pi = bob.start_cfgmgr()
- except bind10_src.ProcessStartError as e:
- thrown = True
-
# We just check that an exception was thrown, and that several
# attempts were made to connect.
- self.assertTrue(thrown)
+ with self.assertRaises(bind10_src.ProcessStartError):
+ pi = bob.start_cfgmgr()
+
# 2 seconds of attempts every 1 second should result in 2 attempts
self.assertEqual(attempts, 2)
@@ -1868,12 +1851,12 @@ class TestBossComponents(unittest.TestCase):
bob.start_simple('/bin/true')
self.assertEqual('/bin/true', bob.started_process_name)
self.assertEqual(args, bob.started_process_args)
- self.assertEqual({}, bob.started_process_env)
+ self.assertEqual({'TESTENV': 'A test string'}, bob.started_process_env)
def test_start_simple(self):
'''Test simple process startup.'''
bob = MockBobSimple()
- bob.c_channel_env = {}
+ bob.c_channel_env = {'TESTENV': 'A test string'}
# non-verbose case
self._start_simple_helper(bob, False)
More information about the bind10-changes
mailing list