Skip to content

Commit

Permalink
[WIP] Fix bug in get_connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Éric Lemoine committed Jan 24, 2020
1 parent 6d07b0e commit c3e068c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion procrastinate/aiopg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self, *, socket_timeout: float = store.SOCKET_TIMEOUT, **kwargs: An
self.socket_timeout = socket_timeout

async def get_connection(self, loads=None):
if not self._connection:
if not self._connection or self._connection.closed:
self._connection = await get_connection(
loads=loads, **self._connection_parameters
)
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/test_pg_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,16 @@ async def test_close_connection_no_connection(pg_job_store):
async def test_stop_no_connection(pg_job_store):
pg_job_store.stop()
# Well we didn't crash. Great.


async def test_get_and_close_connection(pg_job_store):
conn1 = await pg_job_store.get_connection(loads=None)
assert not conn1.closed
conn2 = await pg_job_store.get_connection(loads=None)
assert conn2 is conn1
await pg_job_store.close_connection()
assert conn1.closed
conn2 = await pg_job_store.get_connection(loads=None)
assert conn2 is not conn1
await pg_job_store.close_connection()
assert conn2.closed

0 comments on commit c3e068c

Please sign in to comment.