From 207a35f6216203c817b50dc72eaee0e2f42900bc Mon Sep 17 00:00:00 2001 From: Suresh Kumar Date: Sat, 30 Oct 2021 20:43:21 +0530 Subject: [PATCH] added async server cursor close tests for fetchone, fetchmany, fetchall --- tests/test_server_cursor_async.py | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/test_server_cursor_async.py b/tests/test_server_cursor_async.py index a2b5486e1..fc01db25b 100644 --- a/tests/test_server_cursor_async.py +++ b/tests/test_server_cursor_async.py @@ -127,6 +127,52 @@ async def test_close_idempotent(aconn): await cur.close() +async def test_cursor_close_fetchone(aconn): + cur = aconn.cursor("foo") + assert not cur.closed + + query = "select * from generate_series(1, 10)" + await cur.execute(query) + for _ in range(5): + await cur.fetchone() + + await cur.close() + assert cur.closed + + with pytest.raises(e.InterfaceError): + await cur.fetchone() + + +async def test_cursor_close_fetchmany(aconn): + cur = aconn.cursor("foo") + assert not cur.closed + + query = "select * from generate_series(1, 10)" + await cur.execute(query) + assert len(await cur.fetchmany(2)) == 2 + + await cur.close() + assert cur.closed + + with pytest.raises(e.InterfaceError): + await cur.fetchmany(2) + + +async def test_cursor_close_fetchall(aconn): + cur = aconn.cursor("foo") + assert not cur.closed + + query = "select * from generate_series(1, 10)" + await cur.execute(query) + assert len(await cur.fetchall()) == 10 + + await cur.close() + assert cur.closed + + with pytest.raises(e.InterfaceError): + await cur.fetchall() + + async def test_close_noop(aconn, recwarn, retries): async for retry in retries: with retry: -- 2.47.2