Skip to content

Commit

Permalink
Merge pull request FSX#135 from haizaar/master
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
haizaar committed Nov 30, 2015
2 parents cee6320 + 114bb6d commit 2db55c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion momoko/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def when_available(fut):
log.debug("Obtained connection: %s", conn.fileno)
try:
future_or_result = method(conn, *args, **kwargs)
except psycopg2.Error as error:
except Exception as error:
log.debug("Method failed synchronously")
return self._retry(retry, when_available, conn, keep, future)

Expand Down
29 changes: 25 additions & 4 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,15 @@ def test_getconn_manage_with_exception(self):
pass
self.assertEqual(len(self.db.conns.busy), 0, msg="Some connections were not recycled")

@gen_test
def test_non_psycopg2_errors(self):
"""Testing that non-psycopg2 errors are catched properly"""
try:
sql = yield self.conn.execute("SELECT %s %s;", (1,))
except IndexError:
pass
self.assertEqual(len(self.db.conns.busy), 0, msg="Some connections were not recycled")


class MomokoPoolDataTestProxy(ProxyMixIn, MomokoPoolDataTest):
pass
Expand Down Expand Up @@ -815,14 +824,20 @@ def test_abort_waiting_queue(self):
@gen_test
def test_execute_can_start_before_connection_is_done(self):
db = momoko.Pool(dsn=self.good_dsn, size=1, ioloop=self.io_loop)
db.connect()
f = db.connect()
cursor = yield db.execute("SELECT 1")
self.assertEqual(cursor.fetchone()[0], 1)

# This is to hide tornado warnings about unconsumed futures
try:
yield f
except:
pass

@gen_test
def test_execute_before_connection_is_done_will_error(self):
db = momoko.Pool(dsn=bad_dsn, size=1, ioloop=self.io_loop)
db.connect()
f = db.connect()

try:
yield db.execute("SELECT 1")
Expand All @@ -833,6 +848,12 @@ def test_execute_before_connection_is_done_will_error(self):
except psycopg2.DatabaseError:
pass

# This is to hide tornado warnings about unconsumed futures
try:
yield f
except:
pass


class MomokoPoolVolatileDbTestProxy(ProxyMixIn, MomokoPoolVolatileDbTest):

Expand Down Expand Up @@ -869,13 +890,13 @@ def test_execute_can_fail_after_disconnect_with_no_reconnect(self):
# No start proxy here!
yield gen.sleep(db.reconnect_interval)
f2 = db.execute("SELECT 1")
f3 = db.execute("SELECT 1")

try:
yield [f2, f3]
yield f2
self.fail("Exception should have been raised")
except psycopg2.DatabaseError:
pass

self.assertEqual(len(db.conns.waiting_queue), 0)


Expand Down

0 comments on commit 2db55c5

Please sign in to comment.