Skip to content

Commit 440409b

Browse files
committed
Fix test_prepare_20_concurrent_calls
1 parent c546209 commit 440409b

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

tests/test_prepare.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ async def test_prepare_18_empty_result(self):
354354

355355
async def test_prepare_19_concurrent_calls(self):
356356
st = self.loop.create_task(self.con.fetchval(
357-
'SELECT ROW(pg_sleep(0.02), 1)'))
357+
'SELECT ROW(pg_sleep(0.03), 1)'))
358358

359359
# Wait for some time to make sure the first query is fully
360360
# prepared (!) and is now awaiting the results (!!).
@@ -367,20 +367,26 @@ async def test_prepare_19_concurrent_calls(self):
367367
self.assertEqual(await st, (None, 1))
368368

369369
async def test_prepare_20_concurrent_calls(self):
370-
for methname, val in [('fetch', [(1,)]),
371-
('fetchval', 1),
372-
('fetchrow', (1,))]:
370+
expected = ((None, 1),)
373371

374-
meth = getattr(self.con, methname)
372+
for methname, val in [('fetch', [expected]),
373+
('fetchval', expected[0]),
374+
('fetchrow', expected)]:
375375

376-
vf = self.loop.create_task(meth('SELECT 1'))
377-
await asyncio.sleep(0, loop=self.loop)
376+
with self.subTest(meth=methname):
378377

379-
with self.assertRaisesRegex(asyncpg.InterfaceError,
380-
'another operation'):
381-
await meth('SELECT 2')
378+
meth = getattr(self.con, methname)
382379

383-
self.assertEqual(await vf, val)
380+
vf = self.loop.create_task(
381+
meth('SELECT ROW(pg_sleep(0.03), 1)'))
382+
383+
await asyncio.sleep(0.01, loop=self.loop)
384+
385+
with self.assertRaisesRegex(asyncpg.InterfaceError,
386+
'another operation'):
387+
await meth('SELECT 2')
388+
389+
self.assertEqual(await vf, val)
384390

385391
async def test_prepare_21_errors(self):
386392
stmt = await self.con.prepare('SELECT 10 / $1::int')

0 commit comments

Comments
 (0)