MCPcopy
hub / github.com/pingcap/tidb / MustQuery

Method MustQuery

pkg/testkit/testkit.go:175–218  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

173// MustQuery query the statements and returns result rows.
174// If expected result is set it asserts the query result equals expected result.
175func (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.

Callers 15

TestReplaceTablesFunction · 0.95
TestRestoreAutoIncIDFunction · 0.95
TestAllocatorBoundFunction · 0.95
TestShowViaSQLFunction · 0.95
TestPointGetPlanCacheFunction · 0.95
TestIssue20692Function · 0.95
TestIssue52592Function · 0.95
TestIssue56832Function · 0.95

Calls 9

MustQueryWithContextMethod · 0.95
EnableMethod · 0.80
DisableMethod · 0.80
ResetMethod · 0.65
ContainsMethod · 0.65
CloneMethod · 0.65
CompareMethod · 0.65
CheckMethod · 0.65
RowsMethod · 0.65

Tested by 15

TestReplaceTablesFunction · 0.76
TestRestoreAutoIncIDFunction · 0.76
TestAllocatorBoundFunction · 0.76
TestShowViaSQLFunction · 0.76
TestPointGetPlanCacheFunction · 0.76
TestIssue20692Function · 0.76
TestIssue52592Function · 0.76
TestIssue56832Function · 0.76