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

Proposed by Benji York
Status: Merged
Approved by: Gary Poster
Approved revision: no longer in the source branch.
Merged at revision: 15216
Proposed branch: lp:~benji/launchpad/bug-974617
Merge into: lp:launchpad
Diff against target: 40 lines (+15/-6)
1 file modified
lib/lp/testing/fixture.py (+15/-6)
To merge this branch: bzr merge lp:~benji/launchpad/bug-974617
Reviewer Review Type Date Requested Status
Gary Poster (community) Approve
Review via email: mp+105130@code.launchpad.net

Commit message

Wait for pgbouncer to be usable, not just running.

Description of the change

This branch tweaks the code that waits for pgboucer to start for tests to wait for a usable socket to open, not the process itself to have been started. The race between the process starting and it being usable is biting us in tests.

To post a comment you must log in.
Revision history for this message
Gary Poster (gary) wrote :

Ooh, nice! Great idea.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/testing/fixture.py'
2--- lib/lp/testing/fixture.py 2012-04-24 18:00:00 +0000
3+++ lib/lp/testing/fixture.py 2012-05-08 21:10:32 +0000
4@@ -17,6 +17,7 @@
5
6 from ConfigParser import SafeConfigParser
7 import os.path
8+import socket
9 import time
10
11 import amqplib.client_0_8 as amqp
12@@ -128,14 +129,22 @@
13 reconnect_stores()
14
15 def start(self, retries=20, sleep=0.5):
16- """Simply return to simulate an error starting PGBouncer."""
17+ """Start PGBouncer, waiting for it to accept connections if neccesary.
18+ """
19 super(PGBouncerFixture, self).start()
20- for i in itertools.count(1):
21- if self.is_running:
22- return
23- if i == retries:
24- raise PGNotReadyError("Not ready after %d attempts." % i)
25+ s = socket.socket()
26+ for i in xrange(retries):
27+ try:
28+ socket.create_connection((self.host, self.port))
29+ except socket.error:
30+ # Try again.
31+ pass
32+ else:
33+ break
34 time.sleep(sleep)
35+ else:
36+ raise PGNotReadyError("Not ready after %d attempts." % retries)
37+
38
39
40 class ZopeAdapterFixture(Fixture):