Skip to content

Commit 9ddda72

Browse files
committed
explain: fix recently added TestRetryFields
This test rarely flaked because we could see a decimal point in the time spent retrying which the regex didn't account for. This commit fixes the pattern as well as refactors the test to provide more context about the failure to make it easier to understand. An example failure before this change would include the output line like ``` time spent retrying the transaction: 2.8s ``` Release note: None
1 parent 757ce69 commit 9ddda72

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

pkg/sql/opt/exec/explain/output_test.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -360,22 +360,25 @@ func TestRetryFields(t *testing.T) {
360360
sqlDB.Exec(t, "CREATE SEQUENCE s")
361361

362362
retryCountRE := regexp.MustCompile(`number of transaction retries: (\d+)`)
363-
retryTimeRE := regexp.MustCompile(`time spent retrying the transaction: (\d+)[µsm]+`)
364-
queryMatchRE := func(query string) bool {
365-
rows, err := conn.QueryContext(ctx, query)
366-
assert.NoError(t, err)
367-
var foundCount, foundTime bool
368-
for rows.Next() {
369-
var res string
370-
assert.NoError(t, rows.Scan(&res))
371-
if matches := retryCountRE.FindStringSubmatch(res); len(matches) > 0 {
372-
foundCount = true
373-
}
374-
if matches := retryTimeRE.FindStringSubmatch(res); len(matches) > 0 {
375-
foundTime = true
376-
}
363+
retryTimeRE := regexp.MustCompile(`time spent retrying the transaction: ([\d\.]+)[µsm]+`)
364+
365+
const query = "EXPLAIN ANALYZE SELECT IF(nextval('s')<=3, crdb_internal.force_retry('1h'::INTERVAL), 0)"
366+
rows, err := conn.QueryContext(ctx, query)
367+
assert.NoError(t, err)
368+
var output strings.Builder
369+
var foundCount, foundTime bool
370+
for rows.Next() {
371+
var res string
372+
assert.NoError(t, rows.Scan(&res))
373+
output.WriteString(res)
374+
output.WriteString("\n")
375+
if matches := retryCountRE.FindStringSubmatch(res); len(matches) > 0 {
376+
foundCount = true
377+
}
378+
if matches := retryTimeRE.FindStringSubmatch(res); len(matches) > 0 {
379+
foundTime = true
377380
}
378-
return foundCount && foundTime
379381
}
380-
assert.True(t, queryMatchRE("EXPLAIN ANALYZE SELECT IF(nextval('s')<=3, crdb_internal.force_retry('1h'::INTERVAL), 0)"))
382+
assert.Truef(t, foundCount, "expected to find transaction retries, full output:\n\n%s", output.String())
383+
assert.Truef(t, foundTime, "expected to find time spent retrying, full output:\n\n%s", output.String())
381384
}

0 commit comments

Comments
 (0)