Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: migrate test-infra to testify for db_test #32059

Closed
wants to merge 11 commits into from
35 changes: 31 additions & 4 deletions ddl/attributes_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,42 @@ import (
"fmt"
"math"
"testing"
"time"

"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/domain/infosync"
"github.com/pingcap/tidb/store/gcworker"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/util/gcutil"
"github.com/stretchr/testify/require"
)

// MockGC is used to make GC work in the test environment.
func mockGC(tk *testkit.TestKit) (string, string, string, func()) {
originGC := ddl.IsEmulatorGCEnable()
resetGC := func() {
if originGC {
ddl.EmulatorGCEnable()
} else {
ddl.EmulatorGCDisable()
}
}

// disable emulator GC.
// Otherwise emulator GC will delete table record as soon as possible after execute drop table ddl.
ddl.EmulatorGCDisable()
gcTimeFormat := "20060102-15:04:05 -0700 MST"
timeBeforeDrop := time.Now().Add(0 - 48*60*60*time.Second).Format(gcTimeFormat)
timeAfterDrop := time.Now().Add(48 * 60 * 60 * time.Second).Format(gcTimeFormat)
safePointSQL := `INSERT HIGH_PRIORITY INTO mysql.tidb VALUES ('tikv_gc_safe_point', '%[1]s', '')
ON DUPLICATE KEY
UPDATE variable_value = '%[1]s'`
// clear GC variables first.
tk.MustExec("delete from mysql.tidb where variable_name in ( 'tikv_gc_safe_point','tikv_gc_enable' )")
return timeBeforeDrop, timeAfterDrop, safePointSQL, resetGC
}

func TestAlterTableAttributes(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
Expand Down Expand Up @@ -179,7 +206,7 @@ PARTITION BY RANGE (c) (
PARTITION p1 VALUES LESS THAN (11)
);`)

timeBeforeDrop, _, safePointSQL, resetGC := testkit.MockGC(tk)
timeBeforeDrop, _, safePointSQL, resetGC := mockGC(tk)
defer resetGC()

// Set GC safe point
Expand Down Expand Up @@ -222,7 +249,7 @@ PARTITION BY RANGE (c) (
PARTITION p1 VALUES LESS THAN (11)
);`)

timeBeforeDrop, _, safePointSQL, resetGC := testkit.MockGC(tk)
timeBeforeDrop, _, safePointSQL, resetGC := mockGC(tk)
defer resetGC()

// Set GC safe point
Expand Down Expand Up @@ -285,7 +312,7 @@ PARTITION BY RANGE (c) (
failpoint.Disable("github.com/pingcap/tidb/store/gcworker/ignoreDeleteRangeFailed")
}()

timeBeforeDrop, _, safePointSQL, resetGC := testkit.MockGC(tk)
timeBeforeDrop, _, safePointSQL, resetGC := mockGC(tk)
defer resetGC()

// Set GC safe point
Expand Down Expand Up @@ -329,7 +356,7 @@ PARTITION BY RANGE (c) (
failpoint.Disable("github.com/pingcap/tidb/store/gcworker/ignoreDeleteRangeFailed")
}()

timeBeforeDrop, _, safePointSQL, resetGC := testkit.MockGC(tk)
timeBeforeDrop, _, safePointSQL, resetGC := mockGC(tk)
defer resetGC()

// Set GC safe point
Expand Down
Loading