Skip to content

Commit e7a2766

Browse files
committed
fix rename lock test
1 parent 48ae68c commit e7a2766

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

go/logic/applier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
12091209
}
12101210

12111211
this.migrationContext.Log.Infof("Session renameLockSessionId is %+v", *renameLockSessionId)
1212-
// checking the lock holded by rename session
1212+
// Checking the lock is held by rename session
12131213
if *renameLockSessionId > 0 && this.migrationContext.IsOpenMetadataLockInstruments {
12141214
sleepDuration := time.Duration(10*this.migrationContext.CutOverLockTimeoutSeconds) * time.Millisecond
12151215
for i := 1; i <= 100; i++ {

go/logic/migrator_test.go

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/stretchr/testify/suite"
2424
"github.com/testcontainers/testcontainers-go/modules/mysql"
2525

26-
"fmt"
26+
"runtime"
2727

2828
"github.com/github/gh-ost/go/base"
2929
"github.com/github/gh-ost/go/binlog"
@@ -577,36 +577,29 @@ func TestMigratorRetryWithExponentialBackoff(t *testing.T) {
577577
func (suite *MigratorTestSuite) TestCutOverLossDataCaseLockGhostBeforeRename() {
578578
ctx := context.Background()
579579

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()))
581581
suite.Require().NoError(err)
582582

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()))
584584
suite.Require().NoError(err)
585585

586586
done := make(chan error, 1)
587587
go func() {
588-
connectionConfig, err := GetConnectionConfig(ctx, suite.mysqlContainer)
588+
connectionConfig, err := getTestConnectionConfig(ctx, suite.mysqlContainer)
589589
if err != nil {
590590
done <- err
591591
return
592592
}
593-
migrationContext := base.NewMigrationContext()
594-
migrationContext.AllowedRunningOnMaster = true
593+
migrationContext := newTestMigrationContext()
595594
migrationContext.ApplierConnectionConfig = connectionConfig
596595
migrationContext.InspectorConnectionConfig = connectionConfig
597-
migrationContext.DatabaseName = "test"
598-
migrationContext.SkipPortValidation = true
599-
migrationContext.OriginalTableName = "testing"
600596
migrationContext.SetConnectionConfig("innodb")
597+
migrationContext.AllowSetupMetadataLockInstruments = true
601598
migrationContext.AlterStatementOptions = "ADD COLUMN foobar varchar(255)"
602-
migrationContext.ReplicaServerId = 99999
603599
migrationContext.HeartbeatIntervalMilliseconds = 100
604-
migrationContext.ThrottleHTTPIntervalMillis = 100
605-
migrationContext.ThrottleHTTPTimeoutMillis = 1000
606600
migrationContext.CutOverLockTimeoutSeconds = 4
607601

608602
_, filename, _, _ := runtime.Caller(0)
609-
migrationContext.ServeSocketFile = filepath.Join(filepath.Dir(filename), "../../tmp/gh-ost.sock")
610603
migrationContext.PostponeCutOverFlagFile = filepath.Join(filepath.Dir(filename), "../../tmp/ghost.postpone.flag")
611604

612605
migrator := NewMigrator(migrationContext, "0.0.0")
@@ -633,7 +626,7 @@ func (suite *MigratorTestSuite) TestCutOverLossDataCaseLockGhostBeforeRename() {
633626
dmlConn, err := suite.db.Conn(ctx)
634627
suite.Require().NoError(err)
635628

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()))
637630
fmt.Println("insert into table original table")
638631
suite.Require().NoError(err)
639632

@@ -642,20 +635,22 @@ func (suite *MigratorTestSuite) TestCutOverLossDataCaseLockGhostBeforeRename() {
642635

643636
// Verify the new column was added
644637
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)
646641
suite.Require().NoError(err)
647642

648-
err = suite.db.QueryRow("select count(*) from test.testing").Scan(&OriginalValue)
643+
err = suite.db.QueryRow("select count(*) from " + getTestTableName()).Scan(&OriginalValue)
649644
suite.Require().NoError(err)
650645

651646
suite.Require().LessOrEqual(delValue, OriginalValue)
652647

653648
var tableName, createTableSQL string
654649
//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)
656651
suite.Require().NoError(err)
657652

658-
suite.Require().Equal("testing", tableName)
653+
suite.Require().Equal(testMysqlTableName, tableName)
659654
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)
660655
}
661656

0 commit comments

Comments
 (0)