]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
added async server cursor close tests for fetchone, fetchmany, fetchall 126/head
authorSuresh Kumar <sureshdsk91@gmail.com>
Sat, 30 Oct 2021 15:13:21 +0000 (20:43 +0530)
committerSuresh Kumar <sureshdsk91@gmail.com>
Sat, 30 Oct 2021 15:13:21 +0000 (20:43 +0530)
tests/test_server_cursor_async.py

index a2b5486e1e03c036d11774264c0e24a2b7d4a335..fc01db25b9b6ed0573324dfdb9ac7fcab71854c4 100644 (file)
@@ -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: