Skip to content

Commit

Permalink
stmtsummary: fix unstable test (#32434)
Browse files Browse the repository at this point in the history
close #32046
  • Loading branch information
crazycs520 authored Feb 17, 2022
1 parent c8bef98 commit 5e52263
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions util/stmtsummary/statement_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
tidbutil "github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/execdetails"
"github.com/pingcap/tidb/util/plancodec"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -988,11 +989,9 @@ func TestSetMaxStmtCountParallel(t *testing.T) {

threads := 8
loops := 20
wg := sync.WaitGroup{}
wg.Add(threads + 1)
var wg tidbutil.WaitGroupWrapper

addStmtFunc := func() {
defer wg.Done()
stmtExecInfo1 := generateAnyExecInfo()

// Add 32 times with different digest.
Expand All @@ -1002,24 +1001,26 @@ func TestSetMaxStmtCountParallel(t *testing.T) {
}
}
for i := 0; i < threads; i++ {
go addStmtFunc()
wg.Run(addStmtFunc)
}

defer func() {
require.Nil(t, ssMap.SetMaxStmtCount(3000))
require.NoError(t, ssMap.SetMaxStmtCount(3000))
}()

setStmtCountFunc := func() {
defer wg.Done()
// Turn down MaxStmtCount one by one.
for i := 10; i > 0; i-- {
require.Nil(t, ssMap.SetMaxStmtCount(uint(i)))
require.NoError(t, ssMap.SetMaxStmtCount(uint(i)))
}
}
go setStmtCountFunc()
wg.Run(setStmtCountFunc)

wg.Wait()

// add stmt again to make sure evict occurs after SetMaxStmtCount.
addStmtFunc()

reader := newStmtSummaryReaderForTest(ssMap)
datums := reader.GetStmtSummaryCurrentRows()
// due to evictions happened in cache, an additional record will be appended to the table.
Expand Down

0 comments on commit 5e52263

Please sign in to comment.