← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Tim Penhey has proposed merging lp:~thumper/launchpad/fix-branchChanged-scan-request into lp:launchpad/devel with lp:~thumper/launchpad/branch-distro-set-old-mature as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  #636674 branchChanged method fails to create a scan job after scan failure
  https://bugs.launchpad.net/bugs/636674


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
-- 
https://code.launchpad.net/~thumper/launchpad/fix-branchChanged-scan-request/+merge/36096
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~thumper/launchpad/fix-branchChanged-scan-request into lp:launchpad/devel.
=== modified file 'lib/lp/code/model/branch.py'
--- lib/lp/code/model/branch.py	2010-09-09 01:18:36 +0000
+++ lib/lp/code/model/branch.py	2010-09-21 02:53:48 +0000
@@ -990,8 +990,8 @@
             increment = getUtility(IBranchPuller).MIRROR_TIME_INCREMENT
             self.next_mirror_time = (
                 datetime.now(pytz.timezone('UTC')) + increment)
-        if self.last_mirrored_id != last_revision_id:
-            self.last_mirrored_id = last_revision_id
+        self.last_mirrored_id = last_revision_id
+        if self.last_scanned_id != last_revision_id:
             from lp.code.model.branchjob import BranchScanJob
             BranchScanJob.create(self)
         self.control_format = control_format

=== modified file 'lib/lp/code/model/tests/test_branch.py'
--- lib/lp/code/model/tests/test_branch.py	2010-09-09 02:49:47 +0000
+++ lib/lp/code/model/tests/test_branch.py	2010-09-21 02:53:48 +0000
@@ -231,11 +231,25 @@
         branch = self.factory.makeAnyBranch()
         login_person(branch.owner)
         removeSecurityProxy(branch).last_mirrored_id = 'rev1'
-        jobs = list(getUtility(IBranchScanJobSource).iterReady())
-        self.assertEqual(0, len(jobs))
-        branch.branchChanged('', 'rev1', *self.arbitrary_formats)
-        jobs = list(getUtility(IBranchScanJobSource).iterReady())
-        self.assertEqual(0, len(jobs))
+        removeSecurityProxy(branch).last_scanned_id = 'rev1'
+        jobs = list(getUtility(IBranchScanJobSource).iterReady())
+        self.assertEqual(0, len(jobs))
+        branch.branchChanged('', 'rev1', *self.arbitrary_formats)
+        jobs = list(getUtility(IBranchScanJobSource).iterReady())
+        self.assertEqual(0, len(jobs))
+
+    def test_branchChanged_creates_scan_job_for_broken_scan(self):
+        # branchChanged() if the last_scanned_id is different to the newly
+        # changed revision, then a scan job is created.
+        branch = self.factory.makeAnyBranch()
+        login_person(branch.owner)
+        removeSecurityProxy(branch).last_mirrored_id = 'rev1'
+        removeSecurityProxy(branch).last_scanned_id = 'old'
+        jobs = list(getUtility(IBranchScanJobSource).iterReady())
+        self.assertEqual(0, len(jobs))
+        branch.branchChanged('', 'rev1', *self.arbitrary_formats)
+        jobs = list(getUtility(IBranchScanJobSource).iterReady())
+        self.assertEqual(1, len(jobs))
 
     def test_branchChanged_packs_format(self):
         # branchChanged sets the branch_format etc attributes to the passed in