+import concurrent.futures
import logging
import pytest
assert "[IDLE]" in str(tx)
assert "(terminated)" in str(tx)
+
+
+def test_concurrency(conn):
+ conn.autocommit = True
+
+ def fn(value):
+ with conn.transaction():
+ cur = conn.execute("select %s", (value,))
+ return cur
+
+ values = range(2)
+ with concurrent.futures.ThreadPoolExecutor() as e:
+ cursors = e.map(fn, values)
+ assert sum(cur.fetchone()[0] for cur in cursors) == sum(values)
+import asyncio
import logging
import pytest
assert "[IDLE]" in str(tx)
assert "(terminated)" in str(tx)
+
+
+async def test_concurrency(aconn):
+ await aconn.set_autocommit(True)
+
+ async def fn(value):
+ async with aconn.transaction():
+ cur = await aconn.execute("select %s", (value,))
+ return cur
+
+ values = range(2)
+ cursors = await asyncio.gather(*[fn(value) for value in values])
+ assert sum([(await cur.fetchone())[0] for cur in cursors]) == sum(values)