1111from asyncpg import _testbase as tb
1212
1313
14+ MAX_RUNTIME = 0.5
15+
16+
1417class TestTimeout (tb .ConnectedTestCase ):
1518
1619 async def test_timeout_01 (self ):
1720 for methname in {'fetch' , 'fetchrow' , 'fetchval' , 'execute' }:
1821 with self .assertRaises (asyncio .TimeoutError ), \
19- self .assertRunUnder (0.1 ):
22+ self .assertRunUnder (MAX_RUNTIME ):
2023 meth = getattr (self .con , methname )
2124 await meth ('select pg_sleep(10)' , timeout = 0.02 )
2225 self .assertEqual (await self .con .fetch ('select 1' ), [(1 ,)])
@@ -26,7 +29,7 @@ async def test_timeout_02(self):
2629
2730 for methname in {'fetch' , 'fetchrow' , 'fetchval' }:
2831 with self .assertRaises (asyncio .TimeoutError ), \
29- self .assertRunUnder (0.1 ):
32+ self .assertRunUnder (MAX_RUNTIME ):
3033 meth = getattr (st , methname )
3134 await meth (timeout = 0.02 )
3235 self .assertEqual (await self .con .fetch ('select 1' ), [(1 ,)])
@@ -37,14 +40,14 @@ async def test_timeout_03(self):
3740 await asyncio .sleep (0.05 , loop = self .loop )
3841 task .cancel ()
3942 with self .assertRaises (asyncio .CancelledError ), \
40- self .assertRunUnder (0.1 ):
43+ self .assertRunUnder (MAX_RUNTIME ):
4144 await task
4245 self .assertEqual (await self .con .fetch ('select 1' ), [(1 ,)])
4346
4447 async def test_timeout_04 (self ):
4548 st = await self .con .prepare ('select pg_sleep(10)' , timeout = 0.1 )
4649 with self .assertRaises (asyncio .TimeoutError ), \
47- self .assertRunUnder (0.2 ):
50+ self .assertRunUnder (MAX_RUNTIME ):
4851 async with self .con .transaction ():
4952 async for _ in st .cursor (timeout = 0.1 ): # NOQA
5053 pass
@@ -54,7 +57,7 @@ async def test_timeout_04(self):
5457 async with self .con .transaction ():
5558 cur = await st .cursor ()
5659 with self .assertRaises (asyncio .TimeoutError ), \
57- self .assertRunUnder (0.2 ):
60+ self .assertRunUnder (MAX_RUNTIME ):
5861 await cur .fetch (1 , timeout = 0.1 )
5962 self .assertEqual (await self .con .fetch ('select 1' ), [(1 ,)])
6063
@@ -70,7 +73,7 @@ async def test_timeout_05(self):
7073 async def test_timeout_06 (self ):
7174 async with self .con .transaction ():
7275 with self .assertRaises (asyncio .TimeoutError ), \
73- self .assertRunUnder (0.2 ):
76+ self .assertRunUnder (MAX_RUNTIME ):
7477 async for _ in self .con .cursor ( # NOQA
7578 'select pg_sleep(10)' , timeout = 0.1 ):
7679 pass
@@ -79,25 +82,25 @@ async def test_timeout_06(self):
7982 async with self .con .transaction ():
8083 cur = await self .con .cursor ('select pg_sleep(10)' )
8184 with self .assertRaises (asyncio .TimeoutError ), \
82- self .assertRunUnder (0.2 ):
85+ self .assertRunUnder (MAX_RUNTIME ):
8386 await cur .fetch (1 , timeout = 0.1 )
8487
8588 async with self .con .transaction ():
8689 cur = await self .con .cursor ('select pg_sleep(10)' )
8790 with self .assertRaises (asyncio .TimeoutError ), \
88- self .assertRunUnder (0.2 ):
91+ self .assertRunUnder (MAX_RUNTIME ):
8992 await cur .forward (1 , timeout = 1e-10 )
9093
9194 async with self .con .transaction ():
9295 cur = await self .con .cursor ('select pg_sleep(10)' )
9396 with self .assertRaises (asyncio .TimeoutError ), \
94- self .assertRunUnder (0.2 ):
97+ self .assertRunUnder (MAX_RUNTIME ):
9598 await cur .fetchrow (timeout = 0.1 )
9699
97100 async with self .con .transaction ():
98101 cur = await self .con .cursor ('select pg_sleep(10)' )
99102 with self .assertRaises (asyncio .TimeoutError ), \
100- self .assertRunUnder (0.2 ):
103+ self .assertRunUnder (MAX_RUNTIME ):
101104 await cur .fetchrow (timeout = 0.1 )
102105
103106 with self .assertRaises (asyncpg .InFailedSQLTransactionError ):
@@ -116,7 +119,7 @@ def getExtraConnectOptions(self):
116119 async def test_command_timeout_01 (self ):
117120 for methname in {'fetch' , 'fetchrow' , 'fetchval' , 'execute' }:
118121 with self .assertRaises (asyncio .TimeoutError ), \
119- self .assertRunUnder (0.1 ):
122+ self .assertRunUnder (MAX_RUNTIME ):
120123 meth = getattr (self .con , methname )
121124 await meth ('select pg_sleep(10)' )
122125 self .assertEqual (await self .con .fetch ('select 1' ), [(1 ,)])
0 commit comments