@@ -24,6 +24,7 @@ import (
2424 "github.com/PeerDB-io/peerdb/flow/generated/protos"
2525 "github.com/PeerDB-io/peerdb/flow/model"
2626 "github.com/PeerDB-io/peerdb/flow/otel_metrics"
27+ mysql_validation "github.com/PeerDB-io/peerdb/flow/pkg/mysql"
2728 "github.com/PeerDB-io/peerdb/flow/shared"
2829)
2930
@@ -137,38 +138,6 @@ func TestIntegrationANSIQuotesDDLParsedFromBinlog(t *testing.T) {
137138 }
138139}
139140
140- func sourceHasRegisteredReplica (ctx context.Context , c * MySqlConnector , serverID uint32 ) (bool , error ) {
141- rs , err := c .Execute (ctx , "SHOW REPLICAS" )
142- if err != nil {
143- if rs , err = c .Execute (ctx , "SHOW SLAVE HOSTS" ); err != nil {
144- return false , fmt .Errorf ("failed to query source for registered replicas" )
145- }
146- }
147-
148- serverIDCol := - 1
149- for i , field := range rs .Fields {
150- // Case insensitive match because the column name differs between MySQL and MariaDB.
151- if strings .EqualFold (string (field .Name ), "Server_id" ) {
152- serverIDCol = i
153- break
154- }
155- }
156- if serverIDCol < 0 {
157- return false , fmt .Errorf ("no Server_id column in replica list, got fields %v" , rs .Fields )
158- }
159-
160- for row := range rs .RowNumber () {
161- got , err := rs .GetInt (row , serverIDCol )
162- if err != nil {
163- return false , err
164- }
165- if uint32 (got ) == serverID {
166- return true , nil
167- }
168- }
169- return false , nil
170- }
171-
172141// TestIntegrationConfiguredServerID verifies that an explicitly configured server_id is used for
173142// the binlog connection instead of the legacy random fallback: the source must list a replica
174143// registered with exactly that id.
@@ -193,7 +162,7 @@ func TestIntegrationConfiguredServerID(t *testing.T) {
193162
194163 // The source's replica list can lag briefly after registration, so retry until it shows up.
195164 require .EventuallyWithT (t , func (c * assert.CollectT ) {
196- found , err := sourceHasRegisteredReplica ( ctx , connector , wantServerID )
165+ found , err := mysql_validation . HasReplicaWithServerId ( connector . conn . Load () , wantServerID )
197166 assert .NoError (c , err )
198167 assert .True (c , found , "source does not list a replica registered with server_id %d" , wantServerID )
199168 }, 15 * time .Second , time .Second )
0 commit comments