Merge lp:~james-w/udd/fix-auto-retry into lp:udd

Proposed by James Westby on 2012-07-04
Status: Merged
Approved by: Vincent Ladeuil on 2012-07-04
Approved revision: 605
Merged at revision: 604
Proposed branch: lp:~james-w/udd/fix-auto-retry
Merge into: lp:udd
Diff against target: 108 lines (+44/-8)
2 files modified
udd/icommon.py (+7/-6)
udd/tests/test_status_database.py (+37/-2)
To merge this branch: bzr merge lp:~james-w/udd/fix-auto-retry
Reviewer Review Type Date Requested Status
Vincent Ladeuil 2012-07-04 Approve on 2012-07-04
Review via email: mp+113409@code.launchpad.net

Commit Message

Fix auto retry to only retry things that are marked to be auto retried.

To post a comment you must log in.
lp:~james-w/udd/fix-auto-retry updated on 2012-07-04
605. By James Westby on 2012-07-04

Change the variable name to make the purpose clearer.

Vincent Ladeuil (vila) wrote :

Shame I didn't write those tests in the first place :-/

review: Approve
Jonathan Lange (jml) wrote :

On 4 July 2012 15:37, James Westby <email address hidden> wrote:
> James Westby has proposed merging lp:~james-w/udd/fix-auto-retry into lp:udd.
>
> Requested reviews:
> Ubuntu Distributed Development Developers (udd)
>
> For more details, see:
> https://code.launchpad.net/~james-w/udd/fix-auto-retry/+merge/113409
>
>
> --
> https://code.launchpad.net/~james-w/udd/fix-auto-retry/+merge/113409
> Your team Ubuntu Distributed Development Developers is requested to review the proposed merge of lp:~james-w/udd/fix-auto-retry into lp:udd.
>
> === modified file 'udd/icommon.py'
> --- udd/icommon.py 2012-07-04 11:27:18 +0000
> +++ udd/icommon.py 2012-07-04 14:36:22 +0000
> @@ -768,7 +768,7 @@
> return sig
>
> def _known_auto_retry(self, c, sig):
> - return c.execute(self.RETRY_TABLE_SELECT, (sig,)).get_one()
> + return c.execute(self.RETRY_TABLE_SELECT, (sig,)).get_one() is not None
>

Since this caught us out once, it's probably a good idea to add a
docstring to this method explaining its return type so we aren't
caught out again.

> === modified file 'udd/tests/test_status_database.py'
> --- udd/tests/test_status_database.py 2012-07-02 19:43:28 +0000
> +++ udd/tests/test_status_database.py 2012-07-04 14:36:22 +0000
> @@ -112,7 +112,7 @@
> class TestRetry(TestStatusDb):
>
> def test_known_auto_retry_empty(self):
> - self.assertEquals(False, self.db.known_auto_retry('whatever'))
> + self.assertEquals(False, self.db.known_auto_retry(u'whatever'))
>
> def test_known_auto_retry_known(self):
> sig = u'whatever'
> @@ -123,12 +123,47 @@
> self.db.add_known_auto_retry(u'something')
> self.assertEquals(False, self.db.known_auto_retry(u'something else'))
>
> + def test_attempt_retry_no_auto_retry(self):
> + info = icommon.PackageStatus(u'foo')
> + info.signature = u'aaaa'
...

Good tests, thanks!

If the signature u'aaaa' is special at all, then it should become a
constant or something. If udd already depends on testtools or similar
then it should probably use a factory method.

Thanks,
jml

James Westby (james-w) wrote :

On Thu, 05 Jul 2012 09:04:24 -0000, Jonathan Lange <email address hidden> wrote:
> Since this caught us out once, it's probably a good idea to add a
> docstring to this method explaining its return type so we aren't
> caught out again.

I've added a reference to the public version of the method which is
documented.

> Good tests, thanks!
>
> If the signature u'aaaa' is special at all, then it should become a
> constant or something. If udd already depends on testtools or similar
> then it should probably use a factory method.

It's not special, and the code doesn't currently depend on testtools.

Thanks,

James

Vincent Ladeuil (vila) wrote :

> It's not special,

/me nods

> and the code doesn't currently depend on testtools.

Well, the tests use bzrlib.tests which use testtools, so you can use testtools features if/when needed.

James Westby (james-w) wrote :

On Tue, 10 Jul 2012 12:22:24 -0000, Vincent Ladeuil <email address hidden> wrote:
> Well, the tests use bzrlib.tests which use testtools, so you can use testtools features if/when needed.

Ah, good point.

Thanks,

James

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'udd/icommon.py'
2--- udd/icommon.py 2012-07-04 11:27:18 +0000
3+++ udd/icommon.py 2012-07-04 14:41:20 +0000
4@@ -768,7 +768,7 @@
5 return sig
6
7 def _known_auto_retry(self, c, sig):
8- return c.execute(self.RETRY_TABLE_SELECT, (sig,)).get_one()
9+ return c.execute(self.RETRY_TABLE_SELECT, (sig,)).get_one() is not None
10
11 def known_auto_retry(self, sig):
12 """Is the signature marked for auto-retry?
13@@ -779,11 +779,11 @@
14 :rtype: boolean
15 """
16 with Cursor(self.conn) as c:
17- return self._known_auto_retry(c, sig) is not None
18+ return self._known_auto_retry(c, sig)
19
20 def _add_known_auto_retry(self, c, sig):
21- row = self._known_auto_retry(c, sig)
22- if not row:
23+ already_added = self._known_auto_retry(c, sig)
24+ if not already_added:
25 c.execute(self.RETRY_TABLE_INSERT, (sig,))
26
27 def add_known_auto_retry(self, sig):
28@@ -870,8 +870,8 @@
29 self._add_job(c, package, job_type)
30
31 def _attempt_retry(self, c, info):
32- row = self._known_auto_retry(c, info.signature)
33- if row:
34+ auto_retry = self._known_auto_retry(c, info.signature)
35+ if not auto_retry:
36 # A failure that is not auto-retried
37 return False
38 info.auto_retry = True
39@@ -888,6 +888,7 @@
40 # Already retried MAX_AUTO_RETRY_COUNT times, stop retrying
41 return False
42 self._retry(c, info.name, info.signature, info.timestamp)
43+ return True
44
45 def summarise_failures(self):
46 package_info = []
47
48=== modified file 'udd/tests/test_status_database.py'
49--- udd/tests/test_status_database.py 2012-07-02 19:43:28 +0000
50+++ udd/tests/test_status_database.py 2012-07-04 14:41:20 +0000
51@@ -112,7 +112,7 @@
52 class TestRetry(TestStatusDb):
53
54 def test_known_auto_retry_empty(self):
55- self.assertEquals(False, self.db.known_auto_retry('whatever'))
56+ self.assertEquals(False, self.db.known_auto_retry(u'whatever'))
57
58 def test_known_auto_retry_known(self):
59 sig = u'whatever'
60@@ -123,12 +123,47 @@
61 self.db.add_known_auto_retry(u'something')
62 self.assertEquals(False, self.db.known_auto_retry(u'something else'))
63
64+ def test_attempt_retry_no_auto_retry(self):
65+ info = icommon.PackageStatus(u'foo')
66+ info.signature = u'aaaa'
67+ with icommon.Cursor(self.db.conn) as c:
68+ self.assertEquals(False, self.db._attempt_retry(c, info))
69+
70+ def test_attempt_retry_too_recent(self):
71+ info = icommon.PackageStatus(u'foo')
72+ info.signature = u'aaaa'
73+ info.timestamp = datetime.datetime.utcnow()
74+ self.db.add_known_auto_retry(info.signature)
75+ with icommon.Cursor(self.db.conn) as c:
76+ self.assertEquals(False, self.db._attempt_retry(c, info))
77+
78+ def test_attempt_retry_too_many_times(self):
79+ package_name = u'foo'
80+ info = icommon.PackageStatus(package_name)
81+ info.signature = u'aaaa'
82+ info.timestamp = datetime.datetime.utcnow()
83+ self.db.add_known_auto_retry(info.signature)
84+ with icommon.Cursor(self.db.conn) as c:
85+ c.execute('insert into %s values (?, ?, ?, ?, ?)'
86+ % self.db.OLD_FAILURES_TABLE,
87+ (package_name, info.signature, info.timestamp,
88+ info.timestamp, self.db.MAX_AUTO_RETRY_COUNT))
89+ self.assertEquals(False, self.db._attempt_retry(c, info))
90+
91+ def test_attempt_retry_with_auto_retry(self):
92+ info = icommon.PackageStatus(u'foo')
93+ info.signature = u'aaaa'
94+ info.timestamp = (datetime.datetime.utcnow()
95+ - datetime.timedelta(seconds=self.db.AUTO_RETRY_SECONDS+1))
96+ self.db.add_known_auto_retry(info.signature)
97+ with icommon.Cursor(self.db.conn) as c:
98+ self.assertEquals(True, self.db._attempt_retry(c, info))
99+
100 # FIXME: Need more tests for the following but they are too hard to test for
101 # now -- vila 20111020
102
103 # retry(self, package, force=False, priority=False, auto=False,
104 # _retry(self, c, package, signature, timestamp, priority=False):
105-# _attempt_retry(self, c, info):
106
107
108 class TestSignatures(TestStatusDb):

Subscribers

People subscribed via source and target branches