@@ -103,13 +103,13 @@ class TestExecuteMany(tb.ConnectedTestCase):
103
103
def setUp (self ):
104
104
super ().setUp ()
105
105
self .loop .run_until_complete (self .con .execute (
106
- 'CREATE TEMP TABLE exmany (a text, b int PRIMARY KEY)' ))
106
+ 'CREATE TABLE exmany (a text, b int PRIMARY KEY)' ))
107
107
108
108
def tearDown (self ):
109
109
self .loop .run_until_complete (self .con .execute ('DROP TABLE exmany' ))
110
110
super ().tearDown ()
111
111
112
- async def test_basic (self ):
112
+ async def test_executemany_basic (self ):
113
113
result = await self .con .executemany ('''
114
114
INSERT INTO exmany VALUES($1, $2)
115
115
''' , [
@@ -139,7 +139,7 @@ async def test_basic(self):
139
139
('a' , 1 ), ('b' , 2 ), ('c' , 3 ), ('d' , 4 )
140
140
])
141
141
142
- async def test_bad_input (self ):
142
+ async def test_executemany_bad_input (self ):
143
143
bad_data = ([1 / 0 ] for v in range (10 ))
144
144
145
145
with self .assertRaises (ZeroDivisionError ):
@@ -154,7 +154,7 @@ async def test_bad_input(self):
154
154
INSERT INTO exmany (b)VALUES($1)
155
155
''' , good_data )
156
156
157
- async def test_server_failure (self ):
157
+ async def test_executemany_server_failure (self ):
158
158
with self .assertRaises (UniqueViolationError ):
159
159
await self .con .executemany ('''
160
160
INSERT INTO exmany VALUES($1, $2)
@@ -164,7 +164,7 @@ async def test_server_failure(self):
164
164
result = await self .con .fetch ('SELECT * FROM exmany' )
165
165
self .assertEqual (result , [])
166
166
167
- async def test_server_failure_after_writes (self ):
167
+ async def test_executemany_server_failure_after_writes (self ):
168
168
with self .assertRaises (UniqueViolationError ):
169
169
await self .con .executemany ('''
170
170
INSERT INTO exmany VALUES($1, $2)
@@ -174,7 +174,7 @@ async def test_server_failure_after_writes(self):
174
174
result = await self .con .fetch ('SELECT b FROM exmany' )
175
175
self .assertEqual (result , [])
176
176
177
- async def test_server_failure_during_writes (self ):
177
+ async def test_executemany_server_failure_during_writes (self ):
178
178
# failure at the beginning, server error detected in the middle
179
179
pos = 0
180
180
@@ -195,23 +195,54 @@ def gen():
195
195
self .assertEqual (result , [])
196
196
self .assertLess (pos , 128 , 'should stop early' )
197
197
198
- async def test_client_failure_after_writes (self ):
198
+ async def test_executemany_client_failure_after_writes (self ):
199
199
with self .assertRaises (ZeroDivisionError ):
200
200
await self .con .executemany ('''
201
201
INSERT INTO exmany VALUES($1, $2)
202
202
''' , (('a' * 32768 , y + y / y ) for y in range (10 , - 1 , - 1 )))
203
203
result = await self .con .fetch ('SELECT b FROM exmany' )
204
204
self .assertEqual (result , [])
205
205
206
- async def test_timeout (self ):
206
+ async def test_executemany_timeout (self ):
207
207
with self .assertRaises (asyncio .TimeoutError ):
208
208
await self .con .executemany ('''
209
- INSERT INTO exmany VALUES(pg_sleep(0.1), $1 )
210
- ''' , [[ x ] for x in range (128 )], timeout = 0.5 )
209
+ INSERT INTO exmany VALUES(pg_sleep(0.1) || $1, $2 )
210
+ ''' , [( 'a' * 32768 , x ) for x in range (128 )], timeout = 0.5 )
211
211
result = await self .con .fetch ('SELECT * FROM exmany' )
212
212
self .assertEqual (result , [])
213
213
214
- async def test_client_failure_in_transaction (self ):
214
+ async def test_executemany_timeout_flow_control (self ):
215
+ event = asyncio .Event ()
216
+
217
+ async def locker ():
218
+ test_func = getattr (self , self ._testMethodName ).__func__
219
+ opts = getattr (test_func , '__connect_options__' , {})
220
+ conn = await self .connect (** opts )
221
+ try :
222
+ tx = conn .transaction ()
223
+ await tx .start ()
224
+ await conn .execute ("UPDATE exmany SET a = '1' WHERE b = 10" )
225
+ event .set ()
226
+ await asyncio .sleep (1 )
227
+ await tx .rollback ()
228
+ finally :
229
+ event .set ()
230
+ await conn .close ()
231
+
232
+ await self .con .executemany ('''
233
+ INSERT INTO exmany VALUES(NULL, $1)
234
+ ''' , [(x ,) for x in range (128 )])
235
+ fut = asyncio .ensure_future (locker ())
236
+ await event .wait ()
237
+ with self .assertRaises (asyncio .TimeoutError ):
238
+ await self .con .executemany ('''
239
+ UPDATE exmany SET a = $1 WHERE b = $2
240
+ ''' , [('a' * 32768 , x ) for x in range (128 )], timeout = 0.5 )
241
+ await fut
242
+ result = await self .con .fetch ('SELECT * FROM exmany WHERE a IS NOT NULL' )
243
+ self .assertEqual (result , [])
244
+
245
+ async def test_executemany_client_failure_in_transaction (self ):
215
246
tx = self .con .transaction ()
216
247
await tx .start ()
217
248
with self .assertRaises (ZeroDivisionError ):
@@ -226,7 +257,7 @@ async def test_client_failure_in_transaction(self):
226
257
result = await self .con .fetch ('SELECT b FROM exmany' )
227
258
self .assertEqual (result , [])
228
259
229
- async def test_client_server_failure_conflict (self ):
260
+ async def test_executemany_client_server_failure_conflict (self ):
230
261
self .con ._transport .set_write_buffer_limits (65536 * 64 , 16384 * 64 )
231
262
with self .assertRaises (UniqueViolationError ):
232
263
await self .con .executemany ('''
@@ -235,7 +266,7 @@ async def test_client_server_failure_conflict(self):
235
266
result = await self .con .fetch ('SELECT b FROM exmany' )
236
267
self .assertEqual (result , [])
237
268
238
- async def test_prepare (self ):
269
+ async def test_executemany_prepare (self ):
239
270
stmt = await self .con .prepare ('''
240
271
INSERT INTO exmany VALUES($1, $2)
241
272
''' )
0 commit comments