11
11
from asyncpg import _testbase as tb
12
12
13
13
14
+ MAX_RUNTIME = 0.5
15
+
16
+
14
17
class TestTimeout (tb .ConnectedTestCase ):
15
18
16
19
async def test_timeout_01 (self ):
17
20
for methname in {'fetch' , 'fetchrow' , 'fetchval' , 'execute' }:
18
21
with self .assertRaises (asyncio .TimeoutError ), \
19
- self .assertRunUnder (0.1 ):
22
+ self .assertRunUnder (MAX_RUNTIME ):
20
23
meth = getattr (self .con , methname )
21
24
await meth ('select pg_sleep(10)' , timeout = 0.02 )
22
25
self .assertEqual (await self .con .fetch ('select 1' ), [(1 ,)])
@@ -26,7 +29,7 @@ async def test_timeout_02(self):
26
29
27
30
for methname in {'fetch' , 'fetchrow' , 'fetchval' }:
28
31
with self .assertRaises (asyncio .TimeoutError ), \
29
- self .assertRunUnder (0.1 ):
32
+ self .assertRunUnder (MAX_RUNTIME ):
30
33
meth = getattr (st , methname )
31
34
await meth (timeout = 0.02 )
32
35
self .assertEqual (await self .con .fetch ('select 1' ), [(1 ,)])
@@ -37,14 +40,14 @@ async def test_timeout_03(self):
37
40
await asyncio .sleep (0.05 , loop = self .loop )
38
41
task .cancel ()
39
42
with self .assertRaises (asyncio .CancelledError ), \
40
- self .assertRunUnder (0.1 ):
43
+ self .assertRunUnder (MAX_RUNTIME ):
41
44
await task
42
45
self .assertEqual (await self .con .fetch ('select 1' ), [(1 ,)])
43
46
44
47
async def test_timeout_04 (self ):
45
48
st = await self .con .prepare ('select pg_sleep(10)' , timeout = 0.1 )
46
49
with self .assertRaises (asyncio .TimeoutError ), \
47
- self .assertRunUnder (0.2 ):
50
+ self .assertRunUnder (MAX_RUNTIME ):
48
51
async with self .con .transaction ():
49
52
async for _ in st .cursor (timeout = 0.1 ): # NOQA
50
53
pass
@@ -54,7 +57,7 @@ async def test_timeout_04(self):
54
57
async with self .con .transaction ():
55
58
cur = await st .cursor ()
56
59
with self .assertRaises (asyncio .TimeoutError ), \
57
- self .assertRunUnder (0.2 ):
60
+ self .assertRunUnder (MAX_RUNTIME ):
58
61
await cur .fetch (1 , timeout = 0.1 )
59
62
self .assertEqual (await self .con .fetch ('select 1' ), [(1 ,)])
60
63
@@ -70,7 +73,7 @@ async def test_timeout_05(self):
70
73
async def test_timeout_06 (self ):
71
74
async with self .con .transaction ():
72
75
with self .assertRaises (asyncio .TimeoutError ), \
73
- self .assertRunUnder (0.2 ):
76
+ self .assertRunUnder (MAX_RUNTIME ):
74
77
async for _ in self .con .cursor ( # NOQA
75
78
'select pg_sleep(10)' , timeout = 0.1 ):
76
79
pass
@@ -79,25 +82,25 @@ async def test_timeout_06(self):
79
82
async with self .con .transaction ():
80
83
cur = await self .con .cursor ('select pg_sleep(10)' )
81
84
with self .assertRaises (asyncio .TimeoutError ), \
82
- self .assertRunUnder (0.2 ):
85
+ self .assertRunUnder (MAX_RUNTIME ):
83
86
await cur .fetch (1 , timeout = 0.1 )
84
87
85
88
async with self .con .transaction ():
86
89
cur = await self .con .cursor ('select pg_sleep(10)' )
87
90
with self .assertRaises (asyncio .TimeoutError ), \
88
- self .assertRunUnder (0.2 ):
91
+ self .assertRunUnder (MAX_RUNTIME ):
89
92
await cur .forward (1 , timeout = 1e-10 )
90
93
91
94
async with self .con .transaction ():
92
95
cur = await self .con .cursor ('select pg_sleep(10)' )
93
96
with self .assertRaises (asyncio .TimeoutError ), \
94
- self .assertRunUnder (0.2 ):
97
+ self .assertRunUnder (MAX_RUNTIME ):
95
98
await cur .fetchrow (timeout = 0.1 )
96
99
97
100
async with self .con .transaction ():
98
101
cur = await self .con .cursor ('select pg_sleep(10)' )
99
102
with self .assertRaises (asyncio .TimeoutError ), \
100
- self .assertRunUnder (0.2 ):
103
+ self .assertRunUnder (MAX_RUNTIME ):
101
104
await cur .fetchrow (timeout = 0.1 )
102
105
103
106
with self .assertRaises (asyncpg .InFailedSQLTransactionError ):
@@ -116,7 +119,7 @@ def getExtraConnectOptions(self):
116
119
async def test_command_timeout_01 (self ):
117
120
for methname in {'fetch' , 'fetchrow' , 'fetchval' , 'execute' }:
118
121
with self .assertRaises (asyncio .TimeoutError ), \
119
- self .assertRunUnder (0.1 ):
122
+ self .assertRunUnder (MAX_RUNTIME ):
120
123
meth = getattr (self .con , methname )
121
124
await meth ('select pg_sleep(10)' )
122
125
self .assertEqual (await self .con .fetch ('select 1' ), [(1 ,)])
0 commit comments