@@ -12,14 +12,11 @@ namespace Test
1212 [ Trait ( "Category" , "Replication" ) ]
1313 public class BinlogPositionTest
1414 {
15- private readonly MySQLFixture _mysqlFixture ;
1615 protected readonly ITestOutputHelper _outputHelper ;
1716
1817 public BinlogPositionTest ( ITestOutputHelper outputHelper )
1918 {
2019 _outputHelper = outputHelper ;
21- _mysqlFixture = MySQLFixture . Instance ;
22- using var loggerFactory = LoggerFactory . Create ( builder => builder . AddConsole ( ) ) ;
2320 }
2421
2522 // Unit tests for BinlogPosition class
@@ -98,13 +95,15 @@ public void Properties_CanBeModified()
9895 [ Fact ]
9996 public async Task GetCurrentBinlogPosition_ReturnsValidPosition ( )
10097 {
98+ using var mysqlFixture = MySQLFixture . CreateMySQLFixture ( ) ;
99+
101100 // Execute a simple command to ensure we have binlog activity
102- var cmd = _mysqlFixture . CreateCommand ( ) ;
101+ var cmd = mysqlFixture . CreateCommand ( ) ;
103102 cmd . CommandText = "SELECT 1" ;
104103 await cmd . ExecuteScalarAsync ( ) ;
105104
106105 // Get the current binlog position
107- var client = _mysqlFixture . Client ;
106+ var client = mysqlFixture . Client ;
108107 var currentPosition = client . CurrentPosition ;
109108
110109 // Assert
@@ -117,18 +116,20 @@ public async Task GetCurrentBinlogPosition_ReturnsValidPosition()
117116 [ Fact ]
118117 public async Task BinlogPosition_ShouldAdvanceAfterOperations ( )
119118 {
119+ using var mysqlFixture = MySQLFixture . CreateMySQLFixture ( ) ;
120+
120121 // Get the current binlog position to use as reference
121- var client = _mysqlFixture . Client ;
122+ var client = mysqlFixture . Client ;
122123 var initialPosition = client . CurrentPosition ;
123124 _outputHelper . WriteLine ( $ "Initial binlog position: { initialPosition } ") ;
124125
125126 // Execute an operation to advance binlog position
126- var cmd = _mysqlFixture . CreateCommand ( ) ;
127+ var cmd = mysqlFixture . CreateCommand ( ) ;
127128 cmd . CommandText = "INSERT INTO pet (name, owner, species) VALUES ('TestPet', 'TestOwner', 'TestSpecies')" ;
128129 await cmd . ExecuteNonQueryAsync ( ) ;
129130
130131 // Receive an event to ensure binlog has progressed
131- var eventLog = await _mysqlFixture . ReceiveAsync < WriteRowsEvent > ( ) ;
132+ var eventLog = await mysqlFixture . ReceiveAsync < WriteRowsEvent > ( ) ;
132133 Assert . NotNull ( eventLog ) ;
133134
134135 // Check that position has advanced
@@ -147,8 +148,10 @@ public async Task BinlogPosition_ShouldAdvanceAfterOperations()
147148 [ Fact ]
148149 public async Task PositionChanged_EventFires_WhenPositionChanges ( )
149150 {
151+ using var mysqlFixture = MySQLFixture . CreateMySQLFixture ( ) ;
152+
150153 // Set up event handler to detect position changes
151- var client = _mysqlFixture . Client ;
154+ var client = mysqlFixture . Client ;
152155 var positionChangedEvent = new ManualResetEventSlim ( false ) ;
153156 BinlogPosition capturedPosition = null ;
154157
@@ -162,11 +165,11 @@ public async Task PositionChanged_EventFires_WhenPositionChanges()
162165 try
163166 {
164167 // Execute an operation that will trigger binlog position change
165- var cmd = _mysqlFixture . CreateCommand ( ) ;
168+ var cmd = mysqlFixture . CreateCommand ( ) ;
166169 cmd . CommandText = "INSERT INTO pet (name, owner, species) VALUES ('EventTest', 'EventOwner', 'EventSpecies')" ;
167170 await cmd . ExecuteNonQueryAsync ( ) ;
168171
169- await _mysqlFixture . ReceiveAsync < WriteRowsEvent > ( ) ;
172+ await mysqlFixture . ReceiveAsync < WriteRowsEvent > ( ) ;
170173
171174 // Wait for the position changed event to fire
172175 var eventFired = positionChangedEvent . Wait ( TimeSpan . FromSeconds ( 5 ) ) ;
@@ -186,18 +189,20 @@ public async Task PositionChanged_EventFires_WhenPositionChanges()
186189 [ Fact ]
187190 public async Task RotateEvent_UpdatesBinlogPosition ( )
188191 {
192+ using var mysqlFixture = MySQLFixture . CreateMySQLFixture ( ) ;
193+
189194 // Force a log rotation
190- var cmd = _mysqlFixture . CreateCommand ( ) ;
195+ var cmd = mysqlFixture . CreateCommand ( ) ;
191196 cmd . CommandText = "FLUSH LOGS" ;
192197 await cmd . ExecuteNonQueryAsync ( ) ;
193198
194199 // We should receive a rotate event
195- var rotateEvent = await _mysqlFixture . ReceiveAsync < RotateEvent > ( ) ;
200+ var rotateEvent = await mysqlFixture . ReceiveAsync < RotateEvent > ( ) ;
196201 Assert . NotNull ( rotateEvent ) ;
197202 _outputHelper . WriteLine ( $ "Received rotate event with next log: { rotateEvent . NextBinlogFileName } at position: { rotateEvent . RotatePosition } ") ;
198203
199204 // Get current position after rotation
200- var currentPosition = _mysqlFixture . Client . CurrentPosition ;
205+ var currentPosition = mysqlFixture . Client . CurrentPosition ;
201206 _outputHelper . WriteLine ( $ "Current binlog position after rotation: { currentPosition } ") ;
202207
203208 // The rotate event's next binlog file name should match our current filename
@@ -207,8 +212,10 @@ public async Task RotateEvent_UpdatesBinlogPosition()
207212 [ Fact ]
208213 public async Task ConnectWithBinlogPosition_ShouldStartFromSpecifiedPosition ( )
209214 {
215+ using var mysqlFixture = MySQLFixture . CreateMySQLFixture ( ) ;
216+
210217 // First get the current position from our existing connection to use as reference
211- var currentPosition = _mysqlFixture . Client . CurrentPosition ;
218+ var currentPosition = mysqlFixture . Client . CurrentPosition ;
212219 _outputHelper . WriteLine ( $ "Current binlog position: { currentPosition } ") ;
213220
214221 // Create a new replication client
@@ -235,7 +242,7 @@ public async Task ConnectWithBinlogPosition_ShouldStartFromSpecifiedPosition()
235242 _outputHelper . WriteLine ( $ "Successfully connected with position: { newClient . CurrentPosition } ") ;
236243
237244 // Now insert a record to generate a new event
238- var cmd = _mysqlFixture . CreateCommand ( ) ;
245+ var cmd = mysqlFixture . CreateCommand ( ) ;
239246 cmd . CommandText = "INSERT INTO pet (name, owner, species) VALUES ('PositionTest', 'PositionTestOwner', 'PositionTestSpecies')" ;
240247 await cmd . ExecuteNonQueryAsync ( ) ;
241248
0 commit comments