@@ -250,6 +250,71 @@ public async Task CommandTimeoutResetsOnReadAsync()
250
250
Assert . Equal ( ConnectionState . Open , m_connection . State ) ;
251
251
}
252
252
253
+
254
+ [ Fact ]
255
+ public void TransactionCommandTimeoutWithSleepSync ( )
256
+ {
257
+ using ( var transaction = m_connection . BeginTransaction ( ) )
258
+ using ( var cmd = new MySqlCommand ( "SELECT SLEEP(120);" , m_connection , transaction ) )
259
+ {
260
+ cmd . CommandTimeout = 2 ;
261
+ var sw = Stopwatch . StartNew ( ) ;
262
+ try
263
+ {
264
+ using ( var reader = cmd . ExecuteReader ( ) )
265
+ {
266
+ // shouldn't get here
267
+ Assert . True ( false ) ;
268
+ }
269
+ }
270
+ catch ( MySqlException ex )
271
+ {
272
+ sw . Stop ( ) ;
273
+ Assert . Contains ( "timeout" , ex . Message , StringComparison . OrdinalIgnoreCase ) ;
274
+ #if ! BASELINE
275
+ // https://bugs.mysql.com/bug.php?id=86009
276
+ TestUtilities . AssertDuration ( sw , cmd . CommandTimeout * 1000 - 100 , 500 ) ;
277
+ #endif
278
+ }
279
+ }
280
+
281
+ #if ! BASELINE
282
+ Assert . Equal ( ConnectionState . Closed , m_connection . State ) ;
283
+ #endif
284
+ }
285
+
286
+ [ Fact ]
287
+ public async Task TransactionCommandTimeoutWithSleepAsync ( )
288
+ {
289
+ using ( var transaction = await m_connection . BeginTransactionAsync ( ) )
290
+ using ( var cmd = new MySqlCommand ( "SELECT SLEEP(120);" , m_connection , transaction ) )
291
+ {
292
+ cmd . CommandTimeout = 2 ;
293
+ var sw = Stopwatch . StartNew ( ) ;
294
+ try
295
+ {
296
+ using ( var reader = await cmd . ExecuteReaderAsync ( ) )
297
+ {
298
+ // shouldn't get here
299
+ Assert . True ( false ) ;
300
+ }
301
+ }
302
+ catch ( MySqlException ex )
303
+ {
304
+ sw . Stop ( ) ;
305
+ Assert . Contains ( "timeout" , ex . Message , StringComparison . OrdinalIgnoreCase ) ;
306
+ #if ! BASELINE
307
+ // https://bugs.mysql.com/bug.php?id=86009
308
+ TestUtilities . AssertDuration ( sw , cmd . CommandTimeout * 1000 - 100 , 500 ) ;
309
+ #endif
310
+ }
311
+ }
312
+
313
+ #if ! BASELINE
314
+ Assert . Equal ( ConnectionState . Closed , m_connection . State ) ;
315
+ #endif
316
+ }
317
+
253
318
readonly DatabaseFixture m_database ;
254
319
readonly MySqlConnection m_connection ;
255
320
}
0 commit comments