@@ -27,11 +27,11 @@ public CancellationTests()
2727
2828 // NOTE: Multiple nested classes in order to force tests to run in parallel against each other
2929
30- public class CancelExecuteXWithCommandTimeout : CancellationTests
30+ public class CancelWithCommandTimeout : CancellationTests
3131 {
3232 [ SkipCITheory ]
3333 [ MemberData ( nameof ( GetSyncMethodSteps ) ) ]
34- public void Test ( int step , int method )
34+ public void Execute ( int step , int method )
3535 {
3636 using var connection = new MySqlConnection ( m_csb . ConnectionString ) ;
3737 connection . Open ( ) ;
@@ -50,30 +50,22 @@ public void Test(int step, int method)
5050 command . CommandText = "SELECT 1;" ;
5151 Assert . Equal ( 1 , command . ExecuteScalar ( ) ) ;
5252 }
53- }
5453
55- public class CancelExecuteXWithCancel : CancellationTests
56- {
5754 [ 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 )
6057 {
6158 using var connection = new MySqlConnection ( m_csb . ConnectionString ) ;
6259 connection . Open ( ) ;
6360 using var command = connection . CreateCommand ( ) ;
64- command . CommandTimeout = 10 ;
61+ command . CommandTimeout = 1 ;
6562 command . CommandText = $ "SELECT { 4000 + step } ;";
66- var task = Task . Run ( async ( ) =>
67- {
68- await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
69- command . Cancel ( ) ;
70- } ) ;
7163 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 ) ) ;
7365 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 ) ;
7769
7870 // connection should still be usable
7971 Assert . Equal ( ConnectionState . Open , connection . State ) ;
@@ -82,36 +74,38 @@ public void Test(int step, int method)
8274 }
8375 }
8476
85- public class CancelExecuteXAsyncWithCommandTimeout : CancellationTests
77+ public class CancelWithCancel : CancellationTests
8678 {
8779 [ 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 )
9082 {
9183 using var connection = new MySqlConnection ( m_csb . ConnectionString ) ;
9284 connection . Open ( ) ;
9385 using var command = connection . CreateCommand ( ) ;
94- command . CommandTimeout = 1 ;
86+ command . CommandTimeout = 10 ;
9587 command . CommandText = $ "SELECT { 4000 + step } ;";
88+ var task = Task . Run ( async ( ) =>
89+ {
90+ await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
91+ command . Cancel ( ) ;
92+ } ) ;
9693 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 ) ) ;
9895 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 ( ) ;
10299
103100 // connection should still be usable
104101 Assert . Equal ( ConnectionState . Open , connection . State ) ;
105102 command . CommandText = "SELECT 1;" ;
106103 Assert . Equal ( 1 , command . ExecuteScalar ( ) ) ;
107104 }
108- }
109105
110- public class CancelExecuteXAsyncWithCancel : CancellationTests
111- {
112106 [ SkipCITheory ]
113107 [ MemberData ( nameof ( GetAsyncMethodSteps ) ) ]
114- public async Task Test ( int step , int method )
108+ public async Task ExecuteAsync ( int step , int method )
115109 {
116110 using var connection = new MySqlConnection ( m_csb . ConnectionString ) ;
117111 connection . Open ( ) ;
@@ -323,11 +317,11 @@ public async Task Test(int step, int method)
323317 }
324318 }
325319
326- public class ExecuteXWithCancellationTimeoutIsNegativeOne : CancellationTests
320+ public class WithCancellationTimeoutIsNegativeOne : CancellationTests
327321 {
328322 [ SkipCITheory ]
329323 [ MemberData ( nameof ( GetSyncMethodSteps ) ) ]
330- public void Test ( int step , int method )
324+ public void Execute ( int step , int method )
331325 {
332326 var csb = new MySqlConnectionStringBuilder ( m_csb . ConnectionString ) { CancellationTimeout = - 1 } ;
333327 using var connection = new MySqlConnection ( csb . ConnectionString ) ;
@@ -344,13 +338,10 @@ public void Test(int step, int method)
344338 // connection is unusable
345339 Assert . Equal ( ConnectionState . Closed , connection . State ) ;
346340 }
347- }
348341
349- public class ExecuteXAsyncWithCancellationTimeoutIsNegativeOne : CancellationTests
350- {
351342 [ SkipCITheory ]
352343 [ MemberData ( nameof ( GetAsyncMethodSteps ) ) ]
353- public async Task Test ( int step , int method )
344+ public async Task ExecuteAsync ( int step , int method )
354345 {
355346 var csb = new MySqlConnectionStringBuilder ( m_csb . ConnectionString ) { CancellationTimeout = - 1 } ;
356347 using var connection = new MySqlConnection ( csb . ConnectionString ) ;
0 commit comments