Merge lp:~mwhudson/launchpad/requestMirror-shouldnt-demote-branch into lp:launchpad

Proposed by Michael Hudson-Doyle
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~mwhudson/launchpad/requestMirror-shouldnt-demote-branch
Merge into: lp:launchpad
Diff against target: 51 lines
2 files modified
lib/lp/code/model/branch.py (+8/-2)
lib/lp/code/model/tests/test_branchpuller.py (+20/-0)
To merge this branch: bzr merge lp:~mwhudson/launchpad/requestMirror-shouldnt-demote-branch
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+12561@code.launchpad.net

Commit message

Make requestMirror never move a branch backwards in the list of branches that require mirroring.

To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Hi,

This branch makes requestMirror never make next_mirror_time later than it already is.

The implementation is perhaps a little OTT, but it works (I seem to be in a ORM-hating mode currently...).

Cheers,
mwh

Revision history for this message
Tim Penhey (thumper) wrote :

Awesome.

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 2009-09-25 00:59:30 +0000
3+++ lib/lp/code/model/branch.py 2009-10-01 22:49:12 +0000
4@@ -849,8 +849,14 @@
5 """See `IBranch`."""
6 if self.branch_type == BranchType.REMOTE:
7 raise BranchTypeError(self.unique_name)
8- self.next_mirror_time = UTC_NOW
9- self.syncUpdate()
10+ from canonical.launchpad.interfaces import IStore
11+ IStore(self).find(
12+ Branch,
13+ Branch.id == self.id,
14+ Or(Branch.next_mirror_time > UTC_NOW,
15+ Branch.next_mirror_time == None)
16+ ).set(next_mirror_time=UTC_NOW)
17+ self.next_mirror_time = AutoReload
18 return self.next_mirror_time
19
20 def startMirroring(self):
21
22=== modified file 'lib/lp/code/model/tests/test_branchpuller.py'
23--- lib/lp/code/model/tests/test_branchpuller.py 2009-08-04 05:14:32 +0000
24+++ lib/lp/code/model/tests/test_branchpuller.py 2009-10-01 22:49:12 +0000
25@@ -58,6 +58,26 @@
26 branch.requestMirror()
27 self.assertEqual(UTC_NOW, branch.next_mirror_time)
28
29+ def test_requestMirror_doesnt_demote_branch(self):
30+ # requestMirror() sets the mirror request time to 'now' unless
31+ # next_mirror_time is already in the past, i.e. calling
32+ # requestMirror() doesn't move the branch backwards in the queue of
33+ # branches that need mirroring.
34+ branch = self.makeAnyBranch()
35+ past_time = datetime.now(pytz.UTC) - timedelta(days=1)
36+ removeSecurityProxy(branch).next_mirror_time = past_time
37+ branch.requestMirror()
38+ self.assertEqual(past_time, branch.next_mirror_time)
39+
40+ def test_requestMirror_can_promote_branch(self):
41+ # requestMirror() sets the mirror request time to 'now' if
42+ # next_mirror_time is set and in the future.
43+ branch = self.makeAnyBranch()
44+ future_time = datetime.now(pytz.UTC) - timedelta(days=1)
45+ removeSecurityProxy(branch).next_mirror_time = future_time
46+ branch.requestMirror()
47+ self.assertEqual(UTC_NOW, branch.next_mirror_time)
48+
49 def test_requestMirrorDuringPull(self):
50 """Branches can have mirrors requested while they are being mirrored.
51 If so, they should not be removed from the pull queue when the mirror