Merge lp:~frankban/launchpad/bug-1003040 into lp:launchpad

Proposed by Francesco Banconi
Status: Merged
Approved by: Francesco Banconi
Approved revision: no longer in the source branch.
Merged at revision: 15334
Proposed branch: lp:~frankban/launchpad/bug-1003040
Merge into: lp:launchpad
Diff against target: 65 lines (+21/-19)
1 file modified
lib/lp/services/webapp/tests/test_error.py (+21/-19)
To merge this branch: bzr merge lp:~frankban/launchpad/bug-1003040
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+108005@code.launchpad.net

Commit message

Updated TestDatabaseErrorViews.test_disconnectionerror_view_integration to retry the connection several times after the database is restarted.

Description of the change

= Summary =

TestDatabaseErrorViews.test_disconnectionerror_view_integration fails intermittently/rarely in parallel tests.

== Proposed fix ==

The failure is similar to the one in bug 974617, so the same fix should apply in this case.

== Implementation details ==

lib/lp/services/webapp/tests/test_error.py:
see Proposed fix, abstracting the retry code now used in two places.

== Tests ==

$ bin/test -cvvt lp.services.webapp.tests.test_error.TestDatabaseErrorViews

== Demo and Q/A ==

no qa

== lint ==

Linting changed files:
  lib/lp/services/webapp/tests/test_error.py

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

Looks good.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/services/webapp/tests/test_error.py'
2--- lib/lp/services/webapp/tests/test_error.py 2012-05-15 20:47:25 +0000
3+++ lib/lp/services/webapp/tests/test_error.py 2012-05-30 16:08:21 +0000
4@@ -66,6 +66,24 @@
5 else:
6 self.fail("We should have gotten an HTTP error")
7
8+ def retryConnection(self, url, retries=10):
9+ """Retry to connect to *url* for *retries* times.
10+
11+ Return the file-like object returned by *urllib2.urlopen(url)*.
12+ Raise a TimeoutException if the connection can not be established.
13+ """
14+ for i in xrange(retries):
15+ try:
16+ return urllib2.urlopen(url)
17+ except urllib2.HTTPError as e:
18+ if e.code != httplib.SERVICE_UNAVAILABLE:
19+ raise
20+ time.sleep(1)
21+ else:
22+ raise TimeoutException(
23+ "Launchpad did not come up after {0} attempts."
24+ .format(retries))
25+
26 def test_disconnectionerror_view_integration(self):
27 # Test setup.
28 self.useFixture(Urllib2Fixture())
29@@ -94,7 +112,7 @@
30 self.assertEqual(503, self.getHTTPError(url).code)
31 # When the database is available again, requests succeed.
32 bouncer.start()
33- urllib2.urlopen(url)
34+ self.retryConnection(url)
35
36 def test_disconnectionerror_view(self):
37 request = LaunchpadTestRequest()
38@@ -118,25 +136,9 @@
39 # We keep seeing the correct exception on subsequent requests.
40 self.assertEqual(httplib.SERVICE_UNAVAILABLE,
41 self.getHTTPError(url).code)
42- # When the database is available again...
43+ # When the database is available again, requests succeed.
44 bouncer.start()
45- # ...and Launchpad has succesfully connected to it...
46- retries = 10
47- for i in xrange(retries):
48- try:
49- urllib2.urlopen(url)
50- except urllib2.HTTPError as e:
51- if e.code != httplib.SERVICE_UNAVAILABLE:
52- raise
53- else:
54- break
55- time.sleep(1)
56- else:
57- raise TimeoutException(
58- "Launchpad did not come up after {0} attempts."
59- .format(retries))
60- # ...requests succeed again.
61- urllib2.urlopen(url)
62+ self.retryConnection(url)
63
64 def test_operationalerror_view(self):
65 request = LaunchpadTestRequest()