Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util/stmtsummary: migrate test-infra to testify (part 1) #26870

Merged
merged 5 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
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
22 changes: 18 additions & 4 deletions util/stmtsummary/evicted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ import (
"github.com/pingcap/tidb/types"
)

var _ = Suite(&testStmtSummarySuite{})
feitian124 marked this conversation as resolved.
Show resolved Hide resolved

type testStmtSummarySuite struct {
}

// fake a stmtSummaryByDigest
func newInduceSsbd(beginTime int64, endTime int64) *stmtSummaryByDigest {
newSsbd := &stmtSummaryByDigest{
Expand Down Expand Up @@ -85,7 +90,7 @@ func (s *testStmtSummarySuite) TestMapToEvictedCountDatum(c *C) {
}

// test stmtSummaryByDigestMap.toEvictedCountDatum
match(c, ssMap.ToEvictedCountDatum()[0], expectedEvictedCount...)
matchCheck(c, ssMap.ToEvictedCountDatum()[0], expectedEvictedCount...)

// test multiple intervals
ssMap.Clear()
Expand Down Expand Up @@ -134,7 +139,7 @@ func (s *testStmtSummarySuite) TestMapToEvictedCountDatum(c *C) {
types.NewTime(types.FromGoTime(time.Unix(n+interval, 0)), mysql.TypeTimestamp, types.DefaultFsp),
int64(1),
}
match(c, newlyEvicted, expectedEvictedCount...)
matchCheck(c, newlyEvicted, expectedEvictedCount...)
}

// Test stmtSummaryByDigestEvicted
Expand Down Expand Up @@ -285,7 +290,7 @@ func (s *testStmtSummarySuite) TestEvictedCountDetailed(c *C) {
types.NewTime(types.FromGoTime(time.Unix(n+60, 0)), mysql.TypeTimestamp, types.DefaultFsp),
int64(1),
}
match(c, evictedCountDatum, expectedDatum...)
matchCheck(c, evictedCountDatum, expectedDatum...)
n -= 60
}

Expand All @@ -299,7 +304,7 @@ func (s *testStmtSummarySuite) TestEvictedCountDetailed(c *C) {
}
ssMap.AddStatement(banditSei)
evictedCountDatums = ssMap.ToEvictedCountDatum()
match(c, evictedCountDatums[0], expectedDatum...)
matchCheck(c, evictedCountDatums[0], expectedDatum...)

ssMap.Clear()
other := ssMap.other
Expand Down Expand Up @@ -633,3 +638,12 @@ func getEvicted(ssbdee *stmtSummaryByDigestEvictedElement) string {
buf.WriteString(fmt.Sprintf("{begin: %v, end: %v, count: %v}", ssbdee.beginTime, ssbdee.endTime, len(ssbdee.digestKeyMap)))
return buf.String()
}

func matchCheck(c *C, row []types.Datum, expected ...interface{}) {
c.Assert(len(row), Equals, len(expected))
for i := range row {
got := fmt.Sprintf("%v", row[i].GetValue())
need := fmt.Sprintf("%v", expected[i])
c.Assert(got, Equals, need)
}
}
Loading