Skip to content
Merged
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
39 changes: 36 additions & 3 deletions pkg/ttl/ttlworker/job_manager_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1728,8 +1728,6 @@ func TestJobManagerWithFault(t *testing.T) {
}

stopTestCh := make(chan struct{})
wg := &sync.WaitGroup{}
wg.Add(1)

fault := newFaultWithFilter(func(sql string) bool {
// skip some local only sql, ref `getSession()` in `session.go`
Expand All @@ -1740,6 +1738,10 @@ func TestJobManagerWithFault(t *testing.T) {

return true
}, newFaultWithProbability(faultPercent))

wg := &sync.WaitGroup{}
// start the goroutine to inject fault to managers randomly
wg.Add(1)
go func() {
defer wg.Done()

Expand Down Expand Up @@ -1776,6 +1778,38 @@ func TestJobManagerWithFault(t *testing.T) {
}
}()

// start the goroutine to randomly scale the worker count
wg.Add(1)
go func() {
defer wg.Done()

maxScanWorkerCount := variable.DefTiDBTTLScanWorkerCount * 2
minScanWorkerCount := variable.DefTiDBTTLScanWorkerCount / 2

maxDelWorkerCount := variable.DefTiDBTTLDeleteWorkerCount * 2
minDelWorkerCount := variable.DefTiDBTTLDeleteWorkerCount / 2
faultTicker := time.NewTicker(time.Second)

tk := testkit.NewTestKit(t, store)
for {
select {
case <-stopTestCh:
// Recover to the default count
tk.MustExec("set @@global.tidb_ttl_scan_worker_count = ?", variable.DefTiDBTTLScanWorkerCount)
tk.MustExec("set @@global.tidb_ttl_delete_worker_count = ?", variable.DefTiDBTTLDeleteWorkerCount)

return
case <-faultTicker.C:
scanWorkerCount := rand.Int()%(maxScanWorkerCount-minScanWorkerCount) + minScanWorkerCount
delWorkerCount := rand.Int()%(maxDelWorkerCount-minDelWorkerCount) + minDelWorkerCount

logutil.BgLogger().Info("scale worker count", zap.Int("scanWorkerCount", scanWorkerCount), zap.Int("delWorkerCount", delWorkerCount))
tk.MustExec("set @@global.tidb_ttl_scan_worker_count = ?", scanWorkerCount)
tk.MustExec("set @@global.tidb_ttl_delete_worker_count = ?", delWorkerCount)
}
}
}()

// run the workload goroutine
testStart := time.Now()
for time.Since(testStart) < testDuration {
Expand Down Expand Up @@ -1826,7 +1860,6 @@ func TestJobManagerWithFault(t *testing.T) {
}

logutil.BgLogger().Info("test finished")
stopTestCh <- struct{}{}
close(stopTestCh)

wg.Wait()
Expand Down