Merge lp:~benji/launchpad/bug-974617-5 into lp:launchpad

Proposed by Benji York on 2012-05-15
Status: Merged
Approved by: Gary Poster on 2012-05-15
Approved revision: no longer in the source branch.
Merged at revision: 15257
Proposed branch: lp:~benji/launchpad/bug-974617-5
Merge into: lp:launchpad
Diff against target: 64 lines (+18/-4)
2 files modified
lib/lp/services/webapp/tests/test_error.py (+18/-1)
lib/lp/testing/fixture.py (+0/-3)
To merge this branch: bzr merge lp:~benji/launchpad/bug-974617-5
Reviewer Review Type Date Requested Status
Gary Poster (community) 2012-05-15 Approve on 2012-05-15
Review via email: mp+105893@code.launchpad.net

Description of the Change

This branch is the last fix (I hope) for bug 974617 which turned out to be two race conditions. One on starting pgbouncer (which has already been fixed) and one on LP reconnecting to that restarted pgbouncer.

This branch adds a loop that retries connecting until it succeeds or times out.

Lint: this branch fixes a few lint items and is now lint-free.

Tests: there are no tests for the test changed in this branch (which makes sense) but I interactively tested by wrapping the bouncer.start() call in a thread that waited a few seconds before starting. If those few seconds were less than the timeout, the test passed, if more, the test failed so I feel good about how this works.

To post a comment you must log in.
Gary Poster (gary) wrote :

I asked benji about line 35--the technically superfluous urlopen--and he said it was about readability. That's fine by me, given the relative cost of that line in comparison to the test as a whole.

Thanks, Benji!

review: Approve

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-04-24 18:09:54 +0000
3+++ lib/lp/services/webapp/tests/test_error.py 2012-05-15 20:49:21 +0000
4@@ -9,6 +9,7 @@
5 DisconnectionError,
6 OperationalError,
7 )
8+import time
9 import transaction
10 import urllib2
11
12@@ -117,8 +118,24 @@
13 # We keep seeing the correct exception on subsequent requests.
14 self.assertEqual(httplib.SERVICE_UNAVAILABLE,
15 self.getHTTPError(url).code)
16- # When the database is available again, requests succeed.
17+ # When the database is available again...
18 bouncer.start()
19+ # ...and Launchpad has succesfully connected to it...
20+ retries = 10
21+ for i in xrange(retries):
22+ try:
23+ urllib2.urlopen(url)
24+ except urllib2.HTTPError as e:
25+ if e.code != httplib.SERVICE_UNAVAILABLE:
26+ raise
27+ else:
28+ break
29+ time.sleep(1)
30+ else:
31+ raise TimeoutException(
32+ "Launchpad did not come up after {0} attempts."
33+ .format(retries))
34+ # ...requests succeed again.
35 urllib2.urlopen(url)
36
37 def test_operationalerror_view(self):
38
39=== modified file 'lib/lp/testing/fixture.py'
40--- lib/lp/testing/fixture.py 2012-05-08 21:04:08 +0000
41+++ lib/lp/testing/fixture.py 2012-05-15 20:49:21 +0000
42@@ -25,7 +25,6 @@
43 EnvironmentVariableFixture,
44 Fixture,
45 )
46-import itertools
47 from lazr.restful.utils import get_current_browser_request
48 import oops
49 import oops_amqp
50@@ -132,7 +131,6 @@
51 """Start PGBouncer, waiting for it to accept connections if neccesary.
52 """
53 super(PGBouncerFixture, self).start()
54- s = socket.socket()
55 for i in xrange(retries):
56 try:
57 socket.create_connection((self.host, self.port))
58@@ -146,7 +144,6 @@
59 raise PGNotReadyError("Not ready after %d attempts." % retries)
60
61
62-
63 class ZopeAdapterFixture(Fixture):
64 """A fixture to register and unregister an adapter."""
65