diff --git a/pkg/ttl/ttlworker/scan_integration_test.go b/pkg/ttl/ttlworker/scan_integration_test.go index 6bdbb2bcdde7b..acc511bd7e492 100644 --- a/pkg/ttl/ttlworker/scan_integration_test.go +++ b/pkg/ttl/ttlworker/scan_integration_test.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "math/rand/v2" + "strings" "sync" "testing" "time" @@ -26,7 +27,6 @@ import ( "github.com/pingcap/tidb/pkg/sessionctx/vardef" "github.com/pingcap/tidb/pkg/testkit" "github.com/pingcap/tidb/pkg/testkit/testfailpoint" - "github.com/pingcap/tidb/pkg/testkit/testflag" "github.com/pingcap/tidb/pkg/ttl/cache" "github.com/pingcap/tidb/pkg/ttl/ttlworker" "github.com/stretchr/testify/require" @@ -39,11 +39,17 @@ func TestCancelWhileScan(t *testing.T) { tk.MustExec("create table test.t (id int, created_at datetime) TTL= created_at + interval 1 hour") testTable, err := dom.InfoSchema().TableByName(context.Background(), ast.NewCIStr("test"), ast.NewCIStr("t")) require.NoError(t, err) - for i := range 10000 { - tk.MustExec(fmt.Sprintf("insert into test.t values (%d, NOW() - INTERVAL 24 HOUR)", i)) + const totalRows, batchSize = 1000, 100 + for i := 0; i < totalRows; i += batchSize { + values := make([]string, 0, batchSize) + for j := i; j < i+batchSize; j++ { + values = append(values, fmt.Sprintf("(%d, NOW() - INTERVAL 24 HOUR)", j)) + } + tk.MustExec("insert into test.t values " + strings.Join(values, ",")) } testPhysicalTableCache, err := cache.NewPhysicalTable(ast.NewCIStr("test"), testTable.Meta(), ast.NewCIStr("")) require.NoError(t, err) + testfailpoint.Enable(t, "github.com/pingcap/tidb/pkg/store/copr/sleepCoprRequest", "return(200)") delCh := make(chan *ttlworker.TTLDeleteTask) wg := &sync.WaitGroup{} @@ -55,12 +61,8 @@ func TestCancelWhileScan(t *testing.T) { } }() - testStart := time.Now() - testDuration := time.Second - if testflag.Long() { - testDuration = time.Minute - } - for time.Since(testStart) < testDuration { + rounds := 10 + for i := 0; i < rounds; i++ { ctx, cancel := context.WithCancel(context.Background()) ttlTask := ttlworker.NewTTLScanTask(ctx, testPhysicalTableCache, &cache.TTLTask{ JobID: "test",