@@ -27,11 +27,11 @@ public CancellationTests()
27
27
28
28
// NOTE: Multiple nested classes in order to force tests to run in parallel against each other
29
29
30
- public class CancelExecuteXWithCommandTimeout : CancellationTests
30
+ public class CancelWithCommandTimeout : CancellationTests
31
31
{
32
32
[ SkipCITheory ]
33
33
[ MemberData ( nameof ( GetSyncMethodSteps ) ) ]
34
- public void Test ( int step , int method )
34
+ public void Execute ( int step , int method )
35
35
{
36
36
using var connection = new MySqlConnection ( m_csb . ConnectionString ) ;
37
37
connection . Open ( ) ;
@@ -50,30 +50,22 @@ public void Test(int step, int method)
50
50
command . CommandText = "SELECT 1;" ;
51
51
Assert . Equal ( 1 , command . ExecuteScalar ( ) ) ;
52
52
}
53
- }
54
53
55
- public class CancelExecuteXWithCancel : CancellationTests
56
- {
57
54
[ SkipCITheory ]
58
- [ MemberData ( nameof ( GetSyncMethodSteps ) ) ]
59
- public void Test ( int step , int method )
55
+ [ MemberData ( nameof ( GetAsyncMethodSteps ) ) ]
56
+ public async Task ExecuteAsyncs ( int step , int method )
60
57
{
61
58
using var connection = new MySqlConnection ( m_csb . ConnectionString ) ;
62
59
connection . Open ( ) ;
63
60
using var command = connection . CreateCommand ( ) ;
64
- command . CommandTimeout = 10 ;
61
+ command . CommandTimeout = 1 ;
65
62
command . CommandText = $ "SELECT { 4000 + step } ;";
66
- var task = Task . Run ( async ( ) =>
67
- {
68
- await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
69
- command . Cancel ( ) ;
70
- } ) ;
71
63
var stopwatch = Stopwatch . StartNew ( ) ;
72
- var ex = Assert . Throws < MySqlException > ( ( ) => s_executeMethods [ method ] ( command ) ) ;
64
+ var ex = await Assert . ThrowsAsync < MySqlException > ( async ( ) => await s_executeAsyncMethods [ method ] ( command , default ) ) ;
73
65
Assert . InRange ( stopwatch . ElapsedMilliseconds , 900 , 1500 ) ;
74
- Assert . Equal ( MySqlErrorCode . QueryInterrupted , ex . ErrorCode ) ;
75
- Assert . Null ( ex . InnerException ) ;
76
- task . Wait ( ) ;
66
+ Assert . Equal ( MySqlErrorCode . CommandTimeoutExpired , ex . ErrorCode ) ;
67
+ var inner = Assert . IsType < MySqlException > ( ex . InnerException ) ;
68
+ Assert . Equal ( MySqlErrorCode . QueryInterrupted , inner . ErrorCode ) ;
77
69
78
70
// connection should still be usable
79
71
Assert . Equal ( ConnectionState . Open , connection . State ) ;
@@ -82,36 +74,38 @@ public void Test(int step, int method)
82
74
}
83
75
}
84
76
85
- public class CancelExecuteXAsyncWithCommandTimeout : CancellationTests
77
+ public class CancelWithCancel : CancellationTests
86
78
{
87
79
[ SkipCITheory ]
88
- [ MemberData ( nameof ( GetAsyncMethodSteps ) ) ]
89
- public async Task Test ( int step , int method )
80
+ [ MemberData ( nameof ( GetSyncMethodSteps ) ) ]
81
+ public void Execute ( int step , int method )
90
82
{
91
83
using var connection = new MySqlConnection ( m_csb . ConnectionString ) ;
92
84
connection . Open ( ) ;
93
85
using var command = connection . CreateCommand ( ) ;
94
- command . CommandTimeout = 1 ;
86
+ command . CommandTimeout = 10 ;
95
87
command . CommandText = $ "SELECT { 4000 + step } ;";
88
+ var task = Task . Run ( async ( ) =>
89
+ {
90
+ await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
91
+ command . Cancel ( ) ;
92
+ } ) ;
96
93
var stopwatch = Stopwatch . StartNew ( ) ;
97
- var ex = await Assert . ThrowsAsync < MySqlException > ( async ( ) => await s_executeAsyncMethods [ method ] ( command , default ) ) ;
94
+ var ex = Assert . Throws < MySqlException > ( ( ) => s_executeMethods [ method ] ( command ) ) ;
98
95
Assert . InRange ( stopwatch . ElapsedMilliseconds , 900 , 1500 ) ;
99
- Assert . Equal ( MySqlErrorCode . CommandTimeoutExpired , ex . ErrorCode ) ;
100
- var inner = Assert . IsType < MySqlException > ( ex . InnerException ) ;
101
- Assert . Equal ( MySqlErrorCode . QueryInterrupted , inner . ErrorCode ) ;
96
+ Assert . Equal ( MySqlErrorCode . QueryInterrupted , ex . ErrorCode ) ;
97
+ Assert . Null ( ex . InnerException ) ;
98
+ task . Wait ( ) ;
102
99
103
100
// connection should still be usable
104
101
Assert . Equal ( ConnectionState . Open , connection . State ) ;
105
102
command . CommandText = "SELECT 1;" ;
106
103
Assert . Equal ( 1 , command . ExecuteScalar ( ) ) ;
107
104
}
108
- }
109
105
110
- public class CancelExecuteXAsyncWithCancel : CancellationTests
111
- {
112
106
[ SkipCITheory ]
113
107
[ MemberData ( nameof ( GetAsyncMethodSteps ) ) ]
114
- public async Task Test ( int step , int method )
108
+ public async Task ExecuteAsync ( int step , int method )
115
109
{
116
110
using var connection = new MySqlConnection ( m_csb . ConnectionString ) ;
117
111
connection . Open ( ) ;
@@ -323,11 +317,11 @@ public async Task Test(int step, int method)
323
317
}
324
318
}
325
319
326
- public class ExecuteXWithCancellationTimeoutIsNegativeOne : CancellationTests
320
+ public class WithCancellationTimeoutIsNegativeOne : CancellationTests
327
321
{
328
322
[ SkipCITheory ]
329
323
[ MemberData ( nameof ( GetSyncMethodSteps ) ) ]
330
- public void Test ( int step , int method )
324
+ public void Execute ( int step , int method )
331
325
{
332
326
var csb = new MySqlConnectionStringBuilder ( m_csb . ConnectionString ) { CancellationTimeout = - 1 } ;
333
327
using var connection = new MySqlConnection ( csb . ConnectionString ) ;
@@ -344,13 +338,10 @@ public void Test(int step, int method)
344
338
// connection is unusable
345
339
Assert . Equal ( ConnectionState . Closed , connection . State ) ;
346
340
}
347
- }
348
341
349
- public class ExecuteXAsyncWithCancellationTimeoutIsNegativeOne : CancellationTests
350
- {
351
342
[ SkipCITheory ]
352
343
[ MemberData ( nameof ( GetAsyncMethodSteps ) ) ]
353
- public async Task Test ( int step , int method )
344
+ public async Task ExecuteAsync ( int step , int method )
354
345
{
355
346
var csb = new MySqlConnectionStringBuilder ( m_csb . ConnectionString ) { CancellationTimeout = - 1 } ;
356
347
using var connection = new MySqlConnection ( csb . ConnectionString ) ;
0 commit comments