Skip to content

Commit 9afe139

Browse files
committed
tests: Test concurrent operations; test statament survives an error
1 parent 5488705 commit 9afe139

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_prepare.py

+35
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,38 @@ async def test_prepare_18_empty_result(self):
340340
self.assertEqual(await self.con.fetch(''), [])
341341
self.assertIsNone(await self.con.fetchval(''))
342342
self.assertIsNone(await self.con.fetchrow(''))
343+
344+
async def test_prepare_19_concurrent_calls(self):
345+
st = self.loop.create_task(self.con.prepare('SELECT 1'))
346+
await asyncio.sleep(0, loop=self.loop)
347+
348+
with self.assertRaisesRegex(asyncpg.InterfaceError,
349+
'another operation'):
350+
await self.con.execute('SELECT 2')
351+
352+
st = await st
353+
self.assertEqual(await st.fetchval(), 1)
354+
355+
async def test_prepare_20_concurrent_calls(self):
356+
for methname, val in [('fetch', [(1,)]),
357+
('fetchval', 1),
358+
('fetchrow', (1,))]:
359+
360+
meth = getattr(self.con, methname)
361+
362+
vf = self.loop.create_task(meth('SELECT 1'))
363+
await asyncio.sleep(0, loop=self.loop)
364+
365+
with self.assertRaisesRegex(asyncpg.InterfaceError,
366+
'another operation'):
367+
await meth('SELECT 2')
368+
369+
self.assertEqual(await vf, val)
370+
371+
async def test_prepare_21_errors(self):
372+
stmt = await self.con.prepare('SELECT 10 / $1::int')
373+
374+
with self.assertRaises(asyncpg.DivisionByZeroError):
375+
await stmt.fetchval(0)
376+
377+
self.assertEqual(await stmt.fetchval(5), 2)

0 commit comments

Comments
 (0)