@@ -340,3 +340,38 @@ async def test_prepare_18_empty_result(self):
340
340
self .assertEqual (await self .con .fetch ('' ), [])
341
341
self .assertIsNone (await self .con .fetchval ('' ))
342
342
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