Merge lp:~twom/launchpad/precache-gitrepository-branch-queries into lp:launchpad

Proposed by Tom Wardill
Status: Merged
Merged at revision: 18770
Proposed branch: lp:~twom/launchpad/precache-gitrepository-branch-queries
Merge into: lp:launchpad
Diff against target: 58 lines (+6/-4)
3 files modified
lib/lp/code/browser/tests/test_branch.py (+2/-2)
lib/lp/code/browser/tests/test_gitref.py (+2/-2)
lib/lp/code/tests/helpers.py (+2/-0)
To merge this branch: bzr merge lp:~twom/launchpad/precache-gitrepository-branch-queries
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+354470@code.launchpad.net

Commit message

Fix tests broken by the change to a cachedproperty

Description of the change

BranchMergeProposal.votes changed to a cachedproperty, this changes tests to clear that cache once the BMP is loaded and altered.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

I agree with your comment on IRC that it seems like you have too many calls to `clear_property_cache`, and I think that's because you're doing this slightly too far up the call stack. Try instead doing this in `make_merge_proposal_without_reviewers`, though in a more targeted form: `del get_property_cache(proposal).votes` after removing the votes. Then try removing all your `clear_property_cache` calls and see which ones you really need after that.

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/browser/tests/test_branch.py'
--- lib/lp/code/browser/tests/test_branch.py 2018-06-22 10:01:34 +0000
+++ lib/lp/code/browser/tests/test_branch.py 2018-09-07 13:47:31 +0000
@@ -568,7 +568,7 @@
568 view = create_view(branch, '+index')568 view = create_view(branch, '+index')
569 with StormStatementRecorder() as recorder:569 with StormStatementRecorder() as recorder:
570 view.landing_candidates570 view.landing_candidates
571 self.assertThat(recorder, HasQueryCount(Equals(13)))571 self.assertThat(recorder, HasQueryCount(Equals(14)))
572572
573 def test_query_count_landing_targets(self):573 def test_query_count_landing_targets(self):
574 product = self.factory.makeProduct()574 product = self.factory.makeProduct()
@@ -586,7 +586,7 @@
586 view = create_view(branch, '+index')586 view = create_view(branch, '+index')
587 with StormStatementRecorder() as recorder:587 with StormStatementRecorder() as recorder:
588 view.landing_targets588 view.landing_targets
589 self.assertThat(recorder, HasQueryCount(Equals(12)))589 self.assertThat(recorder, HasQueryCount(Equals(13)))
590590
591 def test_query_count_subscriber_content(self):591 def test_query_count_subscriber_content(self):
592 branch = self.factory.makeBranch()592 branch = self.factory.makeBranch()
593593
=== modified file 'lib/lp/code/browser/tests/test_gitref.py'
--- lib/lp/code/browser/tests/test_gitref.py 2018-08-24 16:52:27 +0000
+++ lib/lp/code/browser/tests/test_gitref.py 2018-09-07 13:47:31 +0000
@@ -295,7 +295,7 @@
295 view = create_view(ref, '+index')295 view = create_view(ref, '+index')
296 with StormStatementRecorder() as recorder:296 with StormStatementRecorder() as recorder:
297 view.landing_candidates297 view.landing_candidates
298 self.assertThat(recorder, HasQueryCount(Equals(11)))298 self.assertThat(recorder, HasQueryCount(Equals(12)))
299299
300 def test_query_count_landing_targets(self):300 def test_query_count_landing_targets(self):
301 project = self.factory.makeProduct()301 project = self.factory.makeProduct()
@@ -311,4 +311,4 @@
311 view = create_view(ref, '+index')311 view = create_view(ref, '+index')
312 with StormStatementRecorder() as recorder:312 with StormStatementRecorder() as recorder:
313 view.landing_targets313 view.landing_targets
314 self.assertThat(recorder, HasQueryCount(Equals(11)))314 self.assertThat(recorder, HasQueryCount(Equals(12)))
315315
=== modified file 'lib/lp/code/tests/helpers.py'
--- lib/lp/code/tests/helpers.py 2018-05-17 14:10:29 +0000
+++ lib/lp/code/tests/helpers.py 2018-09-07 13:47:31 +0000
@@ -49,6 +49,7 @@
49from lp.registry.interfaces.pocket import PackagePublishingPocket49from lp.registry.interfaces.pocket import PackagePublishingPocket
50from lp.registry.interfaces.series import SeriesStatus50from lp.registry.interfaces.series import SeriesStatus
51from lp.services.database.sqlbase import cursor51from lp.services.database.sqlbase import cursor
52from lp.services.propertycache import get_property_cache
52from lp.services.memcache.testing import MemcacheFixture53from lp.services.memcache.testing import MemcacheFixture
53from lp.testing import (54from lp.testing import (
54 run_with_login,55 run_with_login,
@@ -275,6 +276,7 @@
275 proposal = factory.makeBranchMergeProposal(**kwargs)276 proposal = factory.makeBranchMergeProposal(**kwargs)
276 for vote in proposal.votes:277 for vote in proposal.votes:
277 removeSecurityProxy(vote).destroySelf()278 removeSecurityProxy(vote).destroySelf()
279 del get_property_cache(proposal).votes
278 return proposal280 return proposal
279281
280282