@@ -23,7 +23,7 @@ import (
23
23
"github.com/stretchr/testify/suite"
24
24
"github.com/testcontainers/testcontainers-go/modules/mysql"
25
25
26
- "fmt "
26
+ "runtime "
27
27
28
28
"github.com/github/gh-ost/go/base"
29
29
"github.com/github/gh-ost/go/binlog"
@@ -577,36 +577,29 @@ func TestMigratorRetryWithExponentialBackoff(t *testing.T) {
577
577
func (suite * MigratorTestSuite ) TestCutOverLossDataCaseLockGhostBeforeRename () {
578
578
ctx := context .Background ()
579
579
580
- _ , err := suite .db .ExecContext (ctx , "CREATE TABLE test.testing (id INT PRIMARY KEY, name VARCHAR(64))" )
580
+ _ , err := suite .db .ExecContext (ctx , fmt . Sprintf ( "CREATE TABLE %s (id INT PRIMARY KEY, name VARCHAR(64))" , getTestTableName ()) )
581
581
suite .Require ().NoError (err )
582
582
583
- _ , err = suite .db .ExecContext (ctx , "insert into test.testing values(1,'a')" )
583
+ _ , err = suite .db .ExecContext (ctx , fmt . Sprintf ( "insert into %s values(1,'a')" , getTestTableName ()) )
584
584
suite .Require ().NoError (err )
585
585
586
586
done := make (chan error , 1 )
587
587
go func () {
588
- connectionConfig , err := GetConnectionConfig (ctx , suite .mysqlContainer )
588
+ connectionConfig , err := getTestConnectionConfig (ctx , suite .mysqlContainer )
589
589
if err != nil {
590
590
done <- err
591
591
return
592
592
}
593
- migrationContext := base .NewMigrationContext ()
594
- migrationContext .AllowedRunningOnMaster = true
593
+ migrationContext := newTestMigrationContext ()
595
594
migrationContext .ApplierConnectionConfig = connectionConfig
596
595
migrationContext .InspectorConnectionConfig = connectionConfig
597
- migrationContext .DatabaseName = "test"
598
- migrationContext .SkipPortValidation = true
599
- migrationContext .OriginalTableName = "testing"
600
596
migrationContext .SetConnectionConfig ("innodb" )
597
+ migrationContext .AllowSetupMetadataLockInstruments = true
601
598
migrationContext .AlterStatementOptions = "ADD COLUMN foobar varchar(255)"
602
- migrationContext .ReplicaServerId = 99999
603
599
migrationContext .HeartbeatIntervalMilliseconds = 100
604
- migrationContext .ThrottleHTTPIntervalMillis = 100
605
- migrationContext .ThrottleHTTPTimeoutMillis = 1000
606
600
migrationContext .CutOverLockTimeoutSeconds = 4
607
601
608
602
_ , filename , _ , _ := runtime .Caller (0 )
609
- migrationContext .ServeSocketFile = filepath .Join (filepath .Dir (filename ), "../../tmp/gh-ost.sock" )
610
603
migrationContext .PostponeCutOverFlagFile = filepath .Join (filepath .Dir (filename ), "../../tmp/ghost.postpone.flag" )
611
604
612
605
migrator := NewMigrator (migrationContext , "0.0.0" )
@@ -633,7 +626,7 @@ func (suite *MigratorTestSuite) TestCutOverLossDataCaseLockGhostBeforeRename() {
633
626
dmlConn , err := suite .db .Conn (ctx )
634
627
suite .Require ().NoError (err )
635
628
636
- _ , err = dmlConn .ExecContext (ctx , "insert into test.testing (id, name) values(2,'b')" )
629
+ _ , err = dmlConn .ExecContext (ctx , fmt . Sprintf ( "insert into %s (id, name) values(2,'b')" , getTestTableName ()) )
637
630
fmt .Println ("insert into table original table" )
638
631
suite .Require ().NoError (err )
639
632
@@ -642,20 +635,22 @@ func (suite *MigratorTestSuite) TestCutOverLossDataCaseLockGhostBeforeRename() {
642
635
643
636
// Verify the new column was added
644
637
var delValue , OriginalValue int64
645
- err = suite .db .QueryRow ("select count(*) from test._testing_del" ).Scan (& delValue )
638
+ err = suite .db .QueryRow (
639
+ fmt .Sprintf ("select count(*) from %s._%s_del" , testMysqlDatabase , testMysqlTableName ),
640
+ ).Scan (& delValue )
646
641
suite .Require ().NoError (err )
647
642
648
- err = suite .db .QueryRow ("select count(*) from test.testing" ).Scan (& OriginalValue )
643
+ err = suite .db .QueryRow ("select count(*) from " + getTestTableName () ).Scan (& OriginalValue )
649
644
suite .Require ().NoError (err )
650
645
651
646
suite .Require ().LessOrEqual (delValue , OriginalValue )
652
647
653
648
var tableName , createTableSQL string
654
649
//nolint:execinquery
655
- err = suite .db .QueryRow ("SHOW CREATE TABLE test.testing" ).Scan (& tableName , & createTableSQL )
650
+ err = suite .db .QueryRow ("SHOW CREATE TABLE " + getTestTableName () ).Scan (& tableName , & createTableSQL )
656
651
suite .Require ().NoError (err )
657
652
658
- suite .Require ().Equal ("testing" , tableName )
653
+ suite .Require ().Equal (testMysqlTableName , tableName )
659
654
suite .Require ().Equal ("CREATE TABLE `testing` (\n `id` int NOT NULL,\n `name` varchar(64) DEFAULT NULL,\n `foobar` varchar(255) DEFAULT NULL,\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" , createTableSQL )
660
655
}
661
656
0 commit comments