Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions pkg/ttl/ttlworker/scan_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"math/rand/v2"
"strings"
"sync"
"testing"
"time"
Expand All @@ -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"
Expand All @@ -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{}
Expand All @@ -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",
Expand Down
Loading