launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #05745
[Merge] lp:~rvb/launchpad/private-ppa-bug-890927 into lp:launchpad
Raphaël Badin has proposed merging lp:~rvb/launchpad/private-ppa-bug-890927 into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/launchpad/private-ppa-bug-890927/+merge/83751
This branch refactors the utility created in lib/lp/soyuz/browser/tests/test_builder_views.py that was used to record the statements issued by running the same method twice, once after having created X elements and the other time after having created Y elements. This is typically used to make sure that the number of statements issued by rendering a page it not impacted by the number of objects displayed on the page.
= Tests =
None.
= Q/A =
None.
--
https://code.launchpad.net/~rvb/launchpad/private-ppa-bug-890927/+merge/83751
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/launchpad/private-ppa-bug-890927 into lp:launchpad.
=== modified file 'lib/lp/soyuz/browser/tests/test_builder_views.py'
--- lib/lp/soyuz/browser/tests/test_builder_views.py 2011-11-28 10:28:54 +0000
+++ lib/lp/soyuz/browser/tests/test_builder_views.py 2011-11-29 10:58:30 +0000
@@ -10,7 +10,6 @@
from zope.component import getUtility
from zope.security.proxy import removeSecurityProxy
-from canonical.database.sqlbase import flush_database_caches
from canonical.launchpad.ftests import login
from canonical.launchpad.webapp.servers import LaunchpadTestRequest
from canonical.testing.layers import LaunchpadFunctionalLayer
@@ -21,7 +20,7 @@
from lp.buildmaster.interfaces.buildfarmjob import IBuildFarmJobSource
from lp.soyuz.browser.builder import BuilderEditView
from lp.testing import (
- StormStatementRecorder,
+ record_two_runs,
TestCaseWithFactory,
)
from lp.testing.fakemethod import FakeMethod
@@ -121,35 +120,15 @@
self.addFakeBuildLog(build)
return build
- def _record_queries_count(self, tested_method, item_creator):
- # A simple helper that returns the two storm statement recorders
- # obtained when running tested_method with {nb_objects} items creater
- # (using item_creator) and then with {nb_objects}*2 items created.
- for i in range(self.nb_objects):
- item_creator()
- # Record how many queries are issued when tested_method is
- # called with {nb_objects} items created.
- flush_database_caches()
- with StormStatementRecorder() as recorder1:
- tested_method()
- # Create {nb_objects} more items.
- for i in range(self.nb_objects):
- item_creator()
- # Record again the number of queries issued.
- flush_database_caches()
- with StormStatementRecorder() as recorder2:
- tested_method()
- return recorder1, recorder2
-
def test_build_history_queries_count_view_recipe_builds(self):
# The builder's history view creation (i.e. the call to
# view.setupBuildList) issues a constant number of queries
# when recipe builds are displayed.
def builder_history_render():
create_initialized_view(self.builder, '+history').render()
- recorder1, recorder2 = self._record_queries_count(
- builder_history_render,
- self.createRecipeBuildWithBuilder)
+ recorder1, recorder2 = record_two_runs(
+ builder_history_render, self.createRecipeBuildWithBuilder,
+ self.nb_objects)
# XXX: rvb 2011-11-14 bug=890326: The only query remaining is the
# one that results from a call to
@@ -163,9 +142,9 @@
# when binary builds are displayed.
def builder_history_render():
create_initialized_view(self.builder, '+history').render()
- recorder1, recorder2 = self._record_queries_count(
- builder_history_render,
- self.createBinaryPackageBuild)
+ recorder1, recorder2 = record_two_runs(
+ builder_history_render, self.createBinaryPackageBuild,
+ self.nb_objects)
self.assertThat(recorder2, HasQueryCount(Equals(recorder1.count)))
@@ -186,8 +165,8 @@
# when translation template builds are displayed.
def builder_history_render():
create_initialized_view(self.builder, '+history').render()
- recorder1, recorder2 = self._record_queries_count(
+ recorder1, recorder2 = record_two_runs(
builder_history_render,
- self.createTranslationTemplateBuildWithBuilder)
+ self.createTranslationTemplateBuildWithBuilder, self.nb_objects)
self.assertThat(recorder2, HasQueryCount(Equals(recorder1.count)))
=== modified file 'lib/lp/soyuz/model/publishing.py'
--- lib/lp/soyuz/model/publishing.py 2011-11-04 12:06:11 +0000
+++ lib/lp/soyuz/model/publishing.py 2011-11-29 10:58:30 +0000
@@ -1844,8 +1844,7 @@
return result_set
- def getChangesFilesForSources(
- self, one_or_more_source_publications):
+ def getChangesFilesForSources(self, one_or_more_source_publications):
"""See `IPublishingSet`."""
# Import PackageUpload and PackageUploadSource locally
# to avoid circular imports, since PackageUpload uses
=== modified file 'lib/lp/testing/__init__.py'
--- lib/lp/testing/__init__.py 2011-11-25 14:54:41 +0000
+++ lib/lp/testing/__init__.py 2011-11-29 10:58:30 +0000
@@ -109,6 +109,7 @@
from zope.testing.testrunner.runner import TestResult as ZopeTestResult
from canonical.config import config
+from canonical.database.sqlbase import flush_database_caches
from canonical.launchpad.webapp import canonical_url
from canonical.launchpad.webapp.adapter import (
print_queries,
@@ -311,6 +312,37 @@
return (ret, recorder.statements)
+def record_two_runs(tested_method, item_creator, first_round_number,
+ second_round_number=None):
+ """A helper that returns the two storm statement recorders
+ obtained when running tested_method after having run the
+ method {item_creator} {first_round_number} times and then
+ again after having run the same method {second_round_number}
+ times.
+
+ :return: a tuple containing the two recorders obtained by the successive
+ runs.
+ """
+ for i in range(first_round_number):
+ item_creator()
+ # Record how many queries are issued when {tested_method} is
+ # called after {item_creator} has been run {first_round_number}
+ # times.
+ flush_database_caches()
+ with StormStatementRecorder() as recorder1:
+ tested_method()
+ # Run {item_creator} {second_round_number} more times.
+ if second_round_number is None:
+ second_round_number = first_round_number
+ for i in range(second_round_number):
+ item_creator()
+ # Record again the number of queries issued.
+ flush_database_caches()
+ with StormStatementRecorder() as recorder2:
+ tested_method()
+ return recorder1, recorder2
+
+
def run_with_storm_debug(function, *args, **kwargs):
"""A helper function to run a function with storm debug tracing on."""
from storm.tracer import debug