1
+ using System . Diagnostics ;
2
+
3
+ namespace IntegrationTests ;
4
+
5
+ public class ServerIdentificationTests : IClassFixture < DatabaseFixture > , IDisposable
6
+ {
7
+ public ServerIdentificationTests ( DatabaseFixture database )
8
+ {
9
+ m_database = database ;
10
+ }
11
+
12
+ public void Dispose ( )
13
+ {
14
+ }
15
+
16
+ [ SkippableFact ( ServerFeatures . Timeout ) ]
17
+ public void CancelCommand_WithServerVerification ( )
18
+ {
19
+ // This test verifies that cancellation still works with server verification
20
+ using var connection = new MySqlConnection ( AppConfig . ConnectionString ) ;
21
+ connection . Open ( ) ;
22
+
23
+ using var cmd = new MySqlCommand ( "SELECT SLEEP(5)" , connection ) ;
24
+ var task = Task . Run ( async ( ) =>
25
+ {
26
+ await Task . Delay ( TimeSpan . FromSeconds ( 0.5 ) ) ;
27
+ cmd . Cancel ( ) ;
28
+ } ) ;
29
+
30
+ var stopwatch = Stopwatch . StartNew ( ) ;
31
+ TestUtilities . AssertExecuteScalarReturnsOneOrIsCanceled ( cmd ) ;
32
+ Assert . InRange ( stopwatch . ElapsedMilliseconds , 250 , 2500 ) ;
33
+
34
+ #pragma warning disable xUnit1031 // Do not use blocking task operations in test method
35
+ task . Wait ( ) ; // shouldn't throw
36
+ #pragma warning restore xUnit1031 // Do not use blocking task operations in test method
37
+
38
+ TestUtilities . LogInfo ( "Cancellation with server verification completed successfully" ) ;
39
+ }
40
+
41
+ [ SkippableFact ( ServerFeatures . KnownCertificateAuthority ) ]
42
+ public void ServerHasServerIdentification ( )
43
+ {
44
+ using var connection = new MySqlConnection ( AppConfig . ConnectionString ) ;
45
+ connection . Open ( ) ;
46
+
47
+ // Test that we can query server identification manually
48
+ using var cmd = new MySqlCommand ( "SELECT @@server_id" , connection ) ;
49
+ var serverId = cmd . ExecuteScalar ( ) ;
50
+ Assert . NotNull ( serverId ) ;
51
+ TestUtilities . LogInfo ( $ "Server ID: { serverId } ") ;
52
+
53
+ // Test server UUID if available (MySQL 5.6+)
54
+ if ( connection . ServerVersion . Version . Major > 5 ||
55
+ ( connection . ServerVersion . Version . Major == 5 && connection . ServerVersion . Version . Minor >= 6 ) )
56
+ {
57
+ try
58
+ {
59
+ using var uuidCmd = new MySqlCommand ( "SELECT @@server_uuid" , connection ) ;
60
+ var serverUuid = uuidCmd . ExecuteScalar ( ) ;
61
+ Assert . NotNull ( serverUuid ) ;
62
+ TestUtilities . LogInfo ( $ "Server UUID: { serverUuid } ") ;
63
+ }
64
+ catch ( MySqlException ex ) when ( ex . ErrorCode == MySqlErrorCode . UnknownSystemVariable )
65
+ {
66
+ // Some MySQL-compatible servers might not support server_uuid
67
+ TestUtilities . LogInfo ( "Server UUID not supported on this server" ) ;
68
+ }
69
+ }
70
+ }
71
+
72
+ private readonly DatabaseFixture m_database ;
73
+ }
0 commit comments