Merge lp:~thumper/launchpad/fix-branchChanged-scan-request into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 11591
Proposed branch: lp:~thumper/launchpad/fix-branchChanged-scan-request
Merge into: lp:launchpad
Prerequisite: lp:~thumper/launchpad/branch-distro-set-old-mature
Diff against target: 49 lines (+21/-7)
2 files modified
lib/lp/code/model/branch.py (+2/-2)
lib/lp/code/model/tests/test_branch.py (+19/-5)
To merge this branch: bzr merge lp:~thumper/launchpad/fix-branchChanged-scan-request
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+36096@code.launchpad.net

Commit message

Request branch scans when branchChanged when the tip is different from the last_scanned_id.

Description of the change

There is a possibility of having two pending scan jobs if the user pushes twice before a scan has occurred, but that is preferable to not creating a scan when we need to.

tests:
  TestBranchChanged

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

nice

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/model/branch.py'
2--- lib/lp/code/model/branch.py 2010-09-09 01:18:36 +0000
3+++ lib/lp/code/model/branch.py 2010-09-21 23:21:49 +0000
4@@ -990,8 +990,8 @@
5 increment = getUtility(IBranchPuller).MIRROR_TIME_INCREMENT
6 self.next_mirror_time = (
7 datetime.now(pytz.timezone('UTC')) + increment)
8- if self.last_mirrored_id != last_revision_id:
9- self.last_mirrored_id = last_revision_id
10+ self.last_mirrored_id = last_revision_id
11+ if self.last_scanned_id != last_revision_id:
12 from lp.code.model.branchjob import BranchScanJob
13 BranchScanJob.create(self)
14 self.control_format = control_format
15
16=== modified file 'lib/lp/code/model/tests/test_branch.py'
17--- lib/lp/code/model/tests/test_branch.py 2010-09-09 02:49:47 +0000
18+++ lib/lp/code/model/tests/test_branch.py 2010-09-21 23:21:49 +0000
19@@ -231,11 +231,25 @@
20 branch = self.factory.makeAnyBranch()
21 login_person(branch.owner)
22 removeSecurityProxy(branch).last_mirrored_id = 'rev1'
23- jobs = list(getUtility(IBranchScanJobSource).iterReady())
24- self.assertEqual(0, len(jobs))
25- branch.branchChanged('', 'rev1', *self.arbitrary_formats)
26- jobs = list(getUtility(IBranchScanJobSource).iterReady())
27- self.assertEqual(0, len(jobs))
28+ removeSecurityProxy(branch).last_scanned_id = 'rev1'
29+ jobs = list(getUtility(IBranchScanJobSource).iterReady())
30+ self.assertEqual(0, len(jobs))
31+ branch.branchChanged('', 'rev1', *self.arbitrary_formats)
32+ jobs = list(getUtility(IBranchScanJobSource).iterReady())
33+ self.assertEqual(0, len(jobs))
34+
35+ def test_branchChanged_creates_scan_job_for_broken_scan(self):
36+ # branchChanged() if the last_scanned_id is different to the newly
37+ # changed revision, then a scan job is created.
38+ branch = self.factory.makeAnyBranch()
39+ login_person(branch.owner)
40+ removeSecurityProxy(branch).last_mirrored_id = 'rev1'
41+ removeSecurityProxy(branch).last_scanned_id = 'old'
42+ jobs = list(getUtility(IBranchScanJobSource).iterReady())
43+ self.assertEqual(0, len(jobs))
44+ branch.branchChanged('', 'rev1', *self.arbitrary_formats)
45+ jobs = list(getUtility(IBranchScanJobSource).iterReady())
46+ self.assertEqual(1, len(jobs))
47
48 def test_branchChanged_packs_format(self):
49 # branchChanged sets the branch_format etc attributes to the passed in