From: Suresh Kumar Date: Sat, 30 Oct 2021 15:13:21 +0000 (+0530) Subject: added async server cursor close tests for fetchone, fetchmany, fetchall X-Git-Tag: 3.0.2~11^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F126%2Fhead;p=thirdparty%2Fpsycopg.git added async server cursor close tests for fetchone, fetchmany, fetchall --- 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: