From fca6b360f591132921acc2301b64989689573e4d Mon Sep 17 00:00:00 2001 From: Rossi Sun Date: Thu, 9 Apr 2026 04:27:47 -0700 Subject: [PATCH 1/2] ttl: stabilize TestCancelWhileScan runtime --- pkg/ttl/ttlworker/scan_integration_test.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/ttl/ttlworker/scan_integration_test.go b/pkg/ttl/ttlworker/scan_integration_test.go index 6bdbb2bcdde7b..f5b0fb7e3fcb2 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" @@ -39,11 +40,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 +62,11 @@ func TestCancelWhileScan(t *testing.T) { } }() - testStart := time.Now() - testDuration := time.Second + rounds := 10 if testflag.Long() { - testDuration = time.Minute + rounds = 30 } - for time.Since(testStart) < testDuration { + for i := 0; i < rounds; i++ { ctx, cancel := context.WithCancel(context.Background()) ttlTask := ttlworker.NewTTLScanTask(ctx, testPhysicalTableCache, &cache.TTLTask{ JobID: "test", From 10aeb41daf90011722bf10c62b400affeb152d3e Mon Sep 17 00:00:00 2001 From: Rossi Sun Date: Tue, 14 Apr 2026 13:57:46 -0700 Subject: [PATCH 2/2] ttl: remove long-mode branch from cancel scan test --- pkg/ttl/ttlworker/scan_integration_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/ttl/ttlworker/scan_integration_test.go b/pkg/ttl/ttlworker/scan_integration_test.go index f5b0fb7e3fcb2..acc511bd7e492 100644 --- a/pkg/ttl/ttlworker/scan_integration_test.go +++ b/pkg/ttl/ttlworker/scan_integration_test.go @@ -27,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" @@ -63,9 +62,6 @@ func TestCancelWhileScan(t *testing.T) { }() rounds := 10 - if testflag.Long() { - rounds = 30 - } for i := 0; i < rounds; i++ { ctx, cancel := context.WithCancel(context.Background()) ttlTask := ttlworker.NewTTLScanTask(ctx, testPhysicalTableCache, &cache.TTLTask{