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

Proposed by Benji York on 2012-05-08
Status: Merged
Approved by: Gary Poster on 2012-05-08
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/ (+15/-6)
To merge this branch: bzr merge lp:~benji/launchpad/bug-974617
Reviewer Review Type Date Requested Status
Gary Poster (community) 2012-05-08 Approve on 2012-05-08
Review via email:

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.
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
=== modified file 'lib/lp/testing/'
--- lib/lp/testing/ 2012-04-24 18:00:00 +0000
+++ lib/lp/testing/ 2012-05-08 21:10:32 +0000
@@ -17,6 +17,7 @@
18from ConfigParser import SafeConfigParser18from ConfigParser import SafeConfigParser
19import os.path19import os.path
20import socket
20import time21import time
22import amqplib.client_0_8 as amqp23import amqplib.client_0_8 as amqp
@@ -128,14 +129,22 @@
128 reconnect_stores()129 reconnect_stores()
130 def start(self, retries=20, sleep=0.5):131 def start(self, retries=20, sleep=0.5):
131 """Simply return to simulate an error starting PGBouncer."""132 """Start PGBouncer, waiting for it to accept connections if neccesary.
133 """
132 super(PGBouncerFixture, self).start()134 super(PGBouncerFixture, self).start()
133 for i in itertools.count(1):135 s = socket.socket()
134 if self.is_running:136 for i in xrange(retries):
135 return137 try:
136 if i == retries:138 socket.create_connection((, self.port))
137 raise PGNotReadyError("Not ready after %d attempts." % i)139 except socket.error:
140 # Try again.
141 pass
142 else:
143 break
138 time.sleep(sleep)144 time.sleep(sleep)
145 else:
146 raise PGNotReadyError("Not ready after %d attempts." % retries)
141class ZopeAdapterFixture(Fixture):150class ZopeAdapterFixture(Fixture):