Rev 4596: Remove duplicate warnings about hpss ratchets by centralising all the ratchets in bzrlib.tests. (Robert Collins) in http://bazaar.launchpad.net/~lifeless/bzr/hpss_ratches
Robert Collins
robertc at robertcollins.net
Mon Aug 10 03:33:27 BST 2009
At http://bazaar.launchpad.net/~lifeless/bzr/hpss_ratches
------------------------------------------------------------
revno: 4596
revision-id: robertc at robertcollins.net-20090810023310-q4e9llcnk7202t7q
parent: pqm at pqm.ubuntu.com-20090807010459-nw1f0r9y1igi19xf
committer: Robert Collins <robertc at robertcollins.net>
branch nick: hpss_ratches
timestamp: Mon 2009-08-10 12:33:10 +1000
message:
Remove duplicate warnings about hpss ratchets by centralising all the ratchets in bzrlib.tests. (Robert Collins)
=== modified file 'NEWS'
--- a/NEWS 2009-08-06 06:58:09 +0000
+++ b/NEWS 2009-08-10 02:33:10 +0000
@@ -199,6 +199,10 @@
Testing
*******
+* HPSS ratchets are now centralised in the ``setup_smart_server_with_call_log``
+ helper method, removing the need to duplicate the warning about changing
+ them throughout the code base. (Robert Collins)
+
* Merge directive cherrypick tests must use the same root id.
(Martin Pool, #409684)
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2009-08-04 11:40:59 +0000
+++ b/bzrlib/tests/__init__.py 2009-08-10 02:33:10 +0000
@@ -2261,7 +2261,12 @@
self.reduceLockdirTimeout()
def setup_smart_server_with_call_log(self):
- """Sets up a smart server as the transport server with a call log."""
+ """Sets up a smart server as the transport server with a call log.
+
+ This is typically used for hpss regression tests, and in addition to
+ setting up the smart server a collection of hpss ratchets are created
+ at self.hpss_ratchets.
+ """
self.transport_server = server.SmartTCPServer_for_testing
self.hpss_calls = []
import traceback
@@ -2273,6 +2278,23 @@
CapturedCall(params, prefix_length))
client._SmartClient.hooks.install_named_hook(
'call', capture_hpss_call, None)
+ # These figures represent the amount of work to perform each use case.
+ # It is entirely ok to reduce a figure if a test fails due to rpc_count
+ # being too low. If the rpc_count increases, more network roundtrips
+ # have become necessary for this use case. Please do not adjust these
+ # figures upwards without agreement from bzr's network support
+ # maintainers.
+ self.hpss_ratchets = {
+ 'push_smart_non_stacked_streaming': Ratchet(self.assertLength, 9),
+ 'push_smart_stacked_streaming': Ratchet(self.assertLength, 14),
+ 'push_smart_tags_streaming': Ratchet(self.assertLength, 11),
+ 'init_on_format': Ratchet(self.assertLength, 2),
+ 'branch_from_trivial_same_server': Ratchet(self.assertLength, 38),
+ 'branch_from_trivial': Ratchet(self.assertLength, 10),
+ 'branch_from_trivial_stacked': Ratchet(self.assertLength, 15),
+ 'pull_smart_stacked': Ratchet(self.assertLength, 18),
+ 'init_repo': Ratchet(self.assertLength, 16),
+ }
def reset_smart_call_log(self):
self.hpss_calls = []
@@ -3900,6 +3922,35 @@
return None
+class Ratchet(object):
+ """A Ratchet separates an assertion from code that needs to check it.
+
+ This is useful to allow checking ratchet style assertions - such as that
+ no more than N round trips are made during an operation, without having
+ the expected values spread out over the code base where the can be changed
+ without reading documentation about them.
+
+ A typical use is to prepare a Ratchet in setUp, and then test it later.
+ """
+
+ def __init__(self, assertion, *args):
+ """Create a ratchet.
+
+ :param assertion: The assertion to invoke when the ratchet is checked.
+ :param *args: positional arguments to pass to the assertion.
+ """
+ self.assertion = assertion
+ self.args = args
+
+ def check(self, *args):
+ """Check the ratchet.
+
+ :param args: Additional arguments to pass to the ratchet. Typically the
+ expected value of the underlying assertion.
+ """
+ return self.assertion(*(self.args + args))
+
+
class _HTTPSServerFeature(Feature):
"""Some tests want an https Server, check if one is available.
=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py 2009-08-03 04:19:03 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py 2009-08-10 02:33:10 +0000
@@ -300,12 +300,7 @@
self.reset_smart_call_log()
out, err = self.run_bzr(['branch', self.get_url('from'),
self.get_url('target')])
- # This figure represent the amount of work to perform this use case. It
- # is entirely ok to reduce this number if a test fails due to rpc_count
- # being too low. If rpc_count increases, more network roundtrips have
- # become necessary for this use case. Please do not adjust this number
- # upwards without agreement from bzr's network support maintainers.
- self.assertLength(38, self.hpss_calls)
+ self.hpss_ratchets['branch_from_trivial_same_server'].check(self.hpss_calls)
def test_branch_from_trivial_branch_streaming_acceptance(self):
self.setup_smart_server_with_call_log()
@@ -315,12 +310,7 @@
self.reset_smart_call_log()
out, err = self.run_bzr(['branch', self.get_url('from'),
'local-target'])
- # This figure represent the amount of work to perform this use case. It
- # is entirely ok to reduce this number if a test fails due to rpc_count
- # being too low. If rpc_count increases, more network roundtrips have
- # become necessary for this use case. Please do not adjust this number
- # upwards without agreement from bzr's network support maintainers.
- self.assertLength(10, self.hpss_calls)
+ self.hpss_ratchets['branch_from_trivial'].check(self.hpss_calls)
def test_branch_from_trivial_stacked_branch_streaming_acceptance(self):
self.setup_smart_server_with_call_log()
@@ -333,12 +323,7 @@
self.reset_smart_call_log()
out, err = self.run_bzr(['branch', self.get_url('feature'),
'local-target'])
- # This figure represent the amount of work to perform this use case. It
- # is entirely ok to reduce this number if a test fails due to rpc_count
- # being too low. If rpc_count increases, more network roundtrips have
- # become necessary for this use case. Please do not adjust this number
- # upwards without agreement from bzr's network support maintainers.
- self.assertLength(15, self.hpss_calls)
+ self.hpss_ratchets['branch_from_trivial_stacked'].check(self.hpss_calls)
class TestRemoteBranch(TestCaseWithSFTPServer):
=== modified file 'bzrlib/tests/blackbox/test_pull.py'
--- a/bzrlib/tests/blackbox/test_pull.py 2009-06-15 06:47:14 +0000
+++ b/bzrlib/tests/blackbox/test_pull.py 2009-08-10 02:33:10 +0000
@@ -382,12 +382,7 @@
self.reset_smart_call_log()
self.run_bzr(['pull', '-r', '1', self.get_url('stacked')],
working_dir='empty')
- # This figure represent the amount of work to perform this use case. It
- # is entirely ok to reduce this number if a test fails due to rpc_count
- # being too low. If rpc_count increases, more network roundtrips have
- # become necessary for this use case. Please do not adjust this number
- # upwards without agreement from bzr's network support maintainers.
- self.assertLength(18, self.hpss_calls)
+ self.hpss_ratchets['pull_smart_stacked'].check(self.hpss_calls)
remote = Branch.open('stacked')
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py 2009-07-22 10:55:35 +0000
+++ b/bzrlib/tests/blackbox/test_push.py 2009-08-10 02:33:10 +0000
@@ -214,12 +214,8 @@
t.commit(allow_pointless=True, message='first commit')
self.reset_smart_call_log()
self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
- # This figure represent the amount of work to perform this use case. It
- # is entirely ok to reduce this number if a test fails due to rpc_count
- # being too low. If rpc_count increases, more network roundtrips have
- # become necessary for this use case. Please do not adjust this number
- # upwards without agreement from bzr's network support maintainers.
- self.assertLength(9, self.hpss_calls)
+ self.hpss_ratchets['push_smart_non_stacked_streaming'].check(
+ self.hpss_calls)
def test_push_smart_stacked_streaming_acceptance(self):
self.setup_smart_server_with_call_log()
@@ -230,12 +226,8 @@
self.reset_smart_call_log()
self.run_bzr(['push', '--stacked', '--stacked-on', '../parent',
self.get_url('public')], working_dir='local')
- # This figure represent the amount of work to perform this use case. It
- # is entirely ok to reduce this number if a test fails due to rpc_count
- # being too low. If rpc_count increases, more network roundtrips have
- # become necessary for this use case. Please do not adjust this number
- # upwards without agreement from bzr's network support maintainers.
- self.assertLength(14, self.hpss_calls)
+ self.hpss_ratchets['push_smart_stacked_streaming'].check(
+ self.hpss_calls)
remote = branch.Branch.open('public')
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
@@ -246,12 +238,7 @@
t.branch.tags.set_tag('new-tag', rev_id)
self.reset_smart_call_log()
self.run_bzr(['push', self.get_url('to-one')], working_dir='from')
- # This figure represent the amount of work to perform this use case. It
- # is entirely ok to reduce this number if a test fails due to rpc_count
- # being too low. If rpc_count increases, more network roundtrips have
- # become necessary for this use case. Please do not adjust this number
- # upwards without agreement from bzr's network support maintainers.
- self.assertLength(11, self.hpss_calls)
+ self.hpss_ratchets['push_smart_tags_streaming'].check(self.hpss_calls)
def test_push_smart_with_default_stacking_url_path_segment(self):
# If the default stacked-on location is a path element then branches
=== modified file 'bzrlib/tests/blackbox/test_shared_repository.py'
--- a/bzrlib/tests/blackbox/test_shared_repository.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/blackbox/test_shared_repository.py 2009-08-10 02:33:10 +0000
@@ -114,9 +114,4 @@
# be fixed.
self.setup_smart_server_with_call_log()
self.run_bzr(['init-repo', self.get_url('repo')])
- # This figure represent the amount of work to perform this use case. It
- # is entirely ok to reduce this number if a test fails due to rpc_count
- # being too low. If rpc_count increases, more network roundtrips have
- # become necessary for this use case. Please do not adjust this number
- # upwards without agreement from bzr's network support maintainers.
- self.assertLength(16, self.hpss_calls)
+ self.hpss_ratchets['init_repo'].check(self.hpss_calls)
=== modified file 'bzrlib/tests/test_bzrdir.py'
--- a/bzrlib/tests/test_bzrdir.py 2009-07-10 07:14:02 +0000
+++ b/bzrlib/tests/test_bzrdir.py 2009-08-10 02:33:10 +0000
@@ -906,13 +906,7 @@
self.reset_smart_call_log()
instance = new_format.initialize_on_transport(transport)
self.assertIsInstance(instance, remote.RemoteBzrDir)
- rpc_count = len(self.hpss_calls)
- # This figure represent the amount of work to perform this use case. It
- # is entirely ok to reduce this number if a test fails due to rpc_count
- # being too low. If rpc_count increases, more network roundtrips have
- # become necessary for this use case. Please do not adjust this number
- # upwards without agreement from bzr's network support maintainers.
- self.assertEqual(2, rpc_count)
+ self.hpss_ratchets['init_on_format'].check(self.hpss_calls)
class TestFormat5(TestCaseWithTransport):
=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py 2009-08-04 02:09:19 +0000
+++ b/bzrlib/tests/test_selftest.py 2009-08-10 02:33:10 +0000
@@ -2297,3 +2297,14 @@
self.verbosity)
tests.run_suite(test, runner_class=MyRunner, stream=StringIO())
self.assertEquals(1, self.calls)
+
+
+class TestRatchet(tests.TestCase):
+
+ def test_ok(self):
+ ratchet = tests.Ratchet(self.assertLength, 3)
+ ratchet.check([1, 2, 3])
+
+ def test_not_ok(self):
+ ratchet = tests.Ratchet(self.assertLength, 3)
+ self.assertRaises(AssertionError, ratchet.check, [1, 2])
More information about the bazaar-commits
mailing list