Rev 5817: (jelmer) Add a tariff test for 'bzr serve --inet'. (Jelmer Vernooij) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed May 4 00:49:28 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5817 [merge]
revision-id: pqm at pqm.ubuntu.com-20110504004926-sxf2v0q9ldwlqm1m
parent: pqm at pqm.ubuntu.com-20110502211354-cbni6j20jyhhmvfw
parent: jelmer at samba.org-20110503222259-fnm025i75gxhsr95
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2011-05-04 00:49:26 +0000
message:
(jelmer) Add a tariff test for 'bzr serve --inet'. (Jelmer Vernooij)
modified:
bzrlib/smart/request.py request.py-20061108095550-gunadhxmzkdjfeek-1
bzrlib/tests/test_import_tariff.py test_import_tariff.p-20100207155145-ff9infp7goncs7zh-1
=== modified file 'bzrlib/smart/request.py'
--- a/bzrlib/smart/request.py 2011-03-03 06:02:49 +0000
+++ b/bzrlib/smart/request.py 2011-05-03 22:22:59 +0000
@@ -31,8 +31,6 @@
# of a SmartServerRequest subclass.
-import tempfile
-import thread
import threading
from bzrlib import (
@@ -48,6 +46,9 @@
from bzrlib.lazy_import import lazy_import
lazy_import(globals(), """
from bzrlib.bundle import serializer
+
+import tempfile
+import thread
""")
=== modified file 'bzrlib/tests/test_import_tariff.py'
--- a/bzrlib/tests/test_import_tariff.py 2011-04-08 14:45:25 +0000
+++ b/bzrlib/tests/test_import_tariff.py 2011-05-03 22:22:59 +0000
@@ -20,6 +20,10 @@
import os
from testtools import content
+from bzrlib.bzrdir import BzrDir
+from bzrlib.smart import medium
+from bzrlib.transport import remote
+
from bzrlib.plugin import (
are_plugins_disabled,
)
@@ -28,6 +32,21 @@
TestCaseWithTransport,
)
+old_format_modules = [
+ 'bzrlib.repofmt.knitrepo',
+ 'bzrlib.repofmt.knitpack_repo',
+ 'bzrlib.plugins.weave_fmt.branch',
+ 'bzrlib.plugins.weave_fmt.bzrdir',
+ 'bzrlib.plugins.weave_fmt.repository',
+ 'bzrlib.plugins.weave_fmt.workingtree',
+ 'bzrlib.weave',
+ 'bzrlib.weavefile',
+ 'bzrlib.xml4',
+ 'bzrlib.xml5',
+ 'bzrlib.xml6',
+ 'bzrlib.xml7',
+ ]
+
class TestImportTariffs(TestCaseWithTransport):
"""Check how many modules are loaded for some representative scenarios.
@@ -43,14 +62,11 @@
self.preserved_env_vars[name] = os.environ.get(name)
super(TestImportTariffs, self).setUp()
- def run_command_check_imports(self, args, forbidden_imports):
- """Run bzr ARGS in a subprocess and check its imports.
+ def start_bzr_subprocess_with_import_check(self, args):
+ """Run a bzr process and capture the imports.
This is fairly expensive because we start a subprocess, so we aim to
cover representative rather than exhaustive cases.
-
- :param forbidden_imports: List of fully-qualified Python module names
- that should not be loaded while running this command.
"""
# We use PYTHON_VERBOSE rather than --profile-importts because in
# experimentation the profile-imports output seems to not always show
@@ -63,10 +79,15 @@
# explicitly do want to test against things installed there, therefore
# we pass it through.
env_changes = dict(PYTHONVERBOSE='1', **self.preserved_env_vars)
- out, err = self.run_bzr_subprocess(args,
- allow_plugins=(not are_plugins_disabled()),
- env_changes=env_changes)
-
+ return self.start_bzr_subprocess(args, env_changes=env_changes,
+ allow_plugins=(not are_plugins_disabled()))
+
+ def check_forbidden_modules(self, err, forbidden_imports):
+ """Check for forbidden modules in stderr.
+
+ :param err: Standard error
+ :param forbidden_imports: List of forbidden modules
+ """
self.addDetail('subprocess_stderr',
content.Content(content.ContentType("text", "plain"),
lambda:[err]))
@@ -77,10 +98,35 @@
bad_modules.append(module_name)
if bad_modules:
- self.fail("command %r loaded forbidden modules %r"
- % (args, bad_modules))
+ self.fail("command loaded forbidden modules %r"
+ % (bad_modules,))
+
+ def finish_bzr_subprocess_with_import_check(self, process,
+ args, forbidden_imports):
+ """Finish subprocess and check specific modules have not been
+ imported.
+
+ :param forbidden_imports: List of fully-qualified Python module names
+ that should not be loaded while running this command.
+ """
+ (out, err) = self.finish_bzr_subprocess(process,
+ universal_newlines=False, process_args=args)
+ self.check_forbidden_modules(err, forbidden_imports)
return out, err
+ def run_command_check_imports(self, args, forbidden_imports):
+ """Run bzr ARGS in a subprocess and check its imports.
+
+ This is fairly expensive because we start a subprocess, so we aim to
+ cover representative rather than exhaustive cases.
+
+ :param forbidden_imports: List of fully-qualified Python module names
+ that should not be loaded while running this command.
+ """
+ process = self.start_bzr_subprocess_with_import_check(args)
+ self.finish_bzr_subprocess_with_import_check(process, args,
+ forbidden_imports)
+
def test_import_tariffs_working(self):
# check some guaranteed-true and false imports to be sure we're
# measuring correctly
@@ -113,8 +159,6 @@
'bzrlib.msgeditor',
'bzrlib.patiencediff',
'bzrlib.remote',
- 'bzrlib.repofmt.knitrepo',
- 'bzrlib.repofmt.knitpack_repo',
'bzrlib.rules',
'bzrlib.sign_my_commits',
'bzrlib.smart',
@@ -123,22 +167,12 @@
'bzrlib.smart.server',
'bzrlib.transform',
'bzrlib.version_info_formats.format_rio',
- 'bzrlib.plugins.weave_fmt.branch',
- 'bzrlib.plugins.weave_fmt.bzrdir',
- 'bzrlib.plugins.weave_fmt.repository',
- 'bzrlib.plugins.weave_fmt.workingtree',
- 'bzrlib.weave',
- 'bzrlib.weavefile',
- 'bzrlib.xml4',
- 'bzrlib.xml5',
- 'bzrlib.xml6',
- 'bzrlib.xml7',
'getpass',
'kerberos',
'smtplib',
'tarfile',
'tempfile',
- ])
+ ] + old_format_modules)
# TODO: similar test for repository-only operations, checking we avoid
# loading wt-specific stuff
#
@@ -149,3 +183,49 @@
self.run_command_check_imports(['help', 'commands'], [
'testtools',
])
+
+ def test_simple_serve(self):
+ # 'serve' in a default format working tree shouldn't need many modules
+ tree = self.make_branch_and_tree('.')
+ process = self.start_bzr_subprocess_with_import_check(['serve',
+ '--inet', '-d', tree.basedir])
+ url = 'bzr://localhost/'
+ self.permit_url(url)
+ client_medium = medium.SmartSimplePipesClientMedium(
+ process.stdout, process.stdin, url)
+ transport = remote.RemoteTransport(url, medium=client_medium)
+ branch = BzrDir.open_from_transport(transport).open_branch()
+ process.stdin.close()
+ # Hide stdin from the subprocess module, so it won't fail to close it.
+ process.stdin = None
+ (out, err) = self.finish_bzr_subprocess(process,
+ universal_newlines=False)
+ self.check_forbidden_modules(err,
+ ['bzrlib.annotate',
+ 'bzrlib.atomicfile',
+ 'bzrlib.bugtracker',
+ 'bzrlib.bundle.commands',
+ 'bzrlib.cmd_version_info',
+ 'bzrlib.externalcommand',
+ 'bzrlib.filters',
+ # foreign branch plugins import the foreign_vcs_registry from
+ # bzrlib.foreign so it can't be blacklisted
+ 'bzrlib.gpg',
+ 'bzrlib.info',
+ 'bzrlib.knit',
+ 'bzrlib.merge3',
+ 'bzrlib.merge_directive',
+ 'bzrlib.msgeditor',
+ 'bzrlib.patiencediff',
+ 'bzrlib.remote',
+ 'bzrlib.rules',
+ 'bzrlib.sign_my_commits',
+ 'bzrlib.smart.client',
+ 'bzrlib.transform',
+ 'bzrlib.version_info_formats.format_rio',
+ 'getpass',
+ 'kerberos',
+ 'smtplib',
+ 'tarfile',
+ 'tempfile',
+ ] + old_format_modules)
More information about the bazaar-commits
mailing list