MustQuery query the statements and returns result rows. If expected result is set it asserts the query result equals expected result.
(sql string, args ...any)
| 173 | // MustQuery query the statements and returns result rows. |
| 174 | // If expected result is set it asserts the query result equals expected result. |
| 175 | func (tk *TestKit) MustQuery(sql string, args ...any) *Result { |
| 176 | defer func() { |
| 177 | if tk.alloc != nil { |
| 178 | tk.alloc.Reset() |
| 179 | } |
| 180 | }() |
| 181 | rs1 := tk.MustQueryWithContext(context.Background(), sql, args...) |
| 182 | if !strings.Contains(sql, "information_schema") || |
| 183 | strings.Contains(sql, "trace") || |
| 184 | strings.Contains(sql, "statements_summary") || |
| 185 | strings.Contains(sql, "slow_query") || |
| 186 | strings.Contains(sql, "cluster_config") || |
| 187 | strings.Contains(sql, "CLUSTER_") || |
| 188 | strings.Contains(sql, "STATEMENTS_SUMMARY_EVICTED") || |
| 189 | strings.Contains(sql, "TIDB_TRX") { |
| 190 | return rs1 |
| 191 | } |
| 192 | err := failpoint.Enable("github.com/pingcap/tidb/pkg/planner/core/skipExtractor", "return(true)") |
| 193 | if err != nil { |
| 194 | panic(err) |
| 195 | } |
| 196 | rs2 := tk.MustQueryWithContext(context.Background(), sql, args...) |
| 197 | err = failpoint.Disable("github.com/pingcap/tidb/pkg/planner/core/skipExtractor") |
| 198 | if err != nil { |
| 199 | panic(err) |
| 200 | } |
| 201 | rs1Row := make([][]string, 0, len(rs1.rows)) |
| 202 | for _, row := range rs1.rows { |
| 203 | rs1SubRow := make([]string, 0, len(row)) |
| 204 | for _, col := range row { |
| 205 | rs1SubRow = append(rs1SubRow, strings.Clone(col)) |
| 206 | } |
| 207 | rs1Row = append(rs1Row, rs1SubRow) |
| 208 | } |
| 209 | slices.SortFunc(rs1.rows, func(a, b []string) int { |
| 210 | return slices.Compare(a, b) |
| 211 | }) |
| 212 | slices.SortFunc(rs2.rows, func(a, b []string) int { |
| 213 | return slices.Compare(a, b) |
| 214 | }) |
| 215 | rs2.Check(rs1.Rows()) |
| 216 | rs1.rows = rs1Row |
| 217 | return rs1 |
| 218 | } |
| 219 | |
| 220 | // EventuallyMustQueryAndCheck query the statements and assert that |
| 221 | // result rows.lt will equal the expected results in waitFor time, periodically checking equality each tick. |