@@ -40,6 +40,7 @@ import (
4040 "github.com/pingcap/tidb/pkg/testkit"
4141 "github.com/pingcap/tidb/pkg/testkit/testfailpoint"
4242 "github.com/pingcap/tidb/pkg/util/logutil"
43+ "github.com/stretchr/testify/assert"
4344 "github.com/stretchr/testify/require"
4445 "go.uber.org/zap"
4546)
@@ -1099,34 +1100,26 @@ func TestIndexUsageWithData(t *testing.T) {
10991100 }
11001101
11011102 checkIndexUsage := func (startQuery time.Time , endQuery time.Time , percentageAccess2050 bool ) {
1102- require .Eventually (t , func () bool {
1103+ require .EventuallyWithT (t , func (c * assert. CollectT ) {
11031104 tk .Session ().ReportUsageStats ()
11041105 rows := tk .MustQuery ("select QUERY_TOTAL,PERCENTAGE_ACCESS_20_50,PERCENTAGE_ACCESS_100,LAST_ACCESS_TIME from information_schema.tidb_index_usage where table_schema = 'test'" ).Rows ()
1105- if len ( rows ) != 1 {
1106- return false
1106+ if ! assert . Len ( c , rows , 1 ) {
1107+ return
11071108 }
11081109 if percentageAccess2050 {
1109- if rows [0 ][1 ] != "1" {
1110- return false
1111- }
1110+ assert .Equal (c , "1" , rows [0 ][1 ])
11121111 } else {
1113- if rows [0 ][1 ] != "0" {
1114- return false
1115- }
1116- }
1117- if rows [0 ][0 ] != "2" || rows [0 ][2 ] != "1" {
1118- return false
1112+ assert .Equal (c , "0" , rows [0 ][1 ])
11191113 }
1114+ assert .Equal (c , "2" , rows [0 ][0 ])
1115+ assert .Equal (c , "1" , rows [0 ][2 ])
11201116 lastAccessTime , err := time .ParseInLocation (time .DateTime , rows [0 ][3 ].(string ), time .Local )
1121- if err != nil {
1122- return false
1117+ if ! assert . NoError ( c , err ) {
1118+ return
11231119 }
1124- if lastAccessTime .Unix () < startQuery .Unix () || lastAccessTime .Unix () > endQuery .Unix () {
1125- return false
1126- }
1127-
1128- return true
1129- }, 10 * time .Second , 100 * time .Millisecond )
1120+ assert .GreaterOrEqual (c , lastAccessTime .Unix (), startQuery .Unix ())
1121+ assert .LessOrEqual (c , lastAccessTime .Unix (), endQuery .Unix ())
1122+ }, 30 * time .Second , 100 * time .Millisecond )
11301123 }
11311124 t .Run ("test index usage with normal index" , func (t * testing.T ) {
11321125 tk .MustExec ("use test" )
0 commit comments