Skip to content

Commit

Permalink
Add one more test. Also both exceptions could be raised
Browse files Browse the repository at this point in the history
  • Loading branch information
Pliner committed Dec 6, 2020
1 parent af7fec3 commit b9146ce
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions tests/test_sa_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async def test_terminate_with_acquired_connections(make_engine):
assert conn.closed


async def test_release_disconnected_connection(
async def test_release_after_connection_disconnected_before_select(
tcp_proxy, unused_port, pg_params, make_engine
):
server_port = pg_params["port"]
Expand All @@ -160,7 +160,7 @@ async def test_release_disconnected_connection(
engine = await make_engine(port=proxy_port)

with pytest.raises(
psycopg2.InterfaceError, match='connection already closed'
(psycopg2.InterfaceError, psycopg2.OperationalError)
):
with pytest.warns(ResourceWarning, match='Invalid transaction status'):
async with engine.acquire() as conn, conn.begin():
Expand All @@ -169,3 +169,24 @@ async def test_release_disconnected_connection(
await conn.execute('SELECT 1;')

assert engine.size == 0


async def test_release_after_connection_disconnected_before_begin(
tcp_proxy, unused_port, pg_params, make_engine
):
server_port = pg_params["port"]
proxy_port = unused_port()

tcp_proxy = await tcp_proxy(proxy_port, server_port)
engine = await make_engine(port=proxy_port)

with pytest.raises(
(psycopg2.InterfaceError, psycopg2.OperationalError)
):
with pytest.warns(ResourceWarning, match='Invalid transaction status'):
async with engine.acquire() as conn:
await conn.execute('SELECT 1;')
await tcp_proxy.disconnect()
async with conn.begin():
pytest.fail("Should not be here")
assert engine.size == 0

0 comments on commit b9146ce

Please sign in to comment.