Skip to content

Commit ae0cb64

Browse files
authored
Merge pull request #160399 from yuzefovich/blathers/backport-release-25.2-160347
release-25.2: roachtest: avoid known problematic pattern in sqlsmith
2 parents f3f1298 + 0004b1e commit ae0cb64

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

pkg/cmd/roachtest/tests/sqlsmith.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/cluster"
1919
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/option"
2020
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/registry"
21+
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestutil"
2122
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/spec"
2223
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test"
2324
"github.com/cockroachdb/cockroach/pkg/internal/sqlsmith"
@@ -204,22 +205,27 @@ WITH into_db = 'defaultdb', unsafe_restore_incompatible_version;
204205
}
205206
}()
206207

207-
stmt = smither.Generate()
208-
if stmt == "" {
209-
// If an empty statement is generated, then ignore it.
210-
done <- errors.Newf("Empty statement returned by generate")
211-
return nil
208+
for {
209+
stmt = smither.Generate()
210+
if stmt == "" {
211+
// If an empty statement is generated, then ignore it.
212+
done <- errors.Newf("Empty statement returned by generate")
213+
return nil
214+
}
215+
if !expectedToTimeout(t, stmt) {
216+
break
217+
}
212218
}
213219

214220
// TODO(yuzefovich): investigate why using the context with
215221
// a timeout results in poisoning the connection (#101208).
216222
_, err := conn.Exec(stmt)
217223
if err == nil {
218224
logStmt(stmt)
219-
stmt = "EXPLAIN " + stmt
220-
_, err = conn.Exec(stmt)
225+
explainStmt := "EXPLAIN " + stmt
226+
_, err = conn.Exec(explainStmt)
221227
if err == nil {
222-
logStmt(stmt)
228+
logStmt(explainStmt)
223229
}
224230
}
225231
done <- err
@@ -349,6 +355,27 @@ WITH into_db = 'defaultdb', unsafe_restore_incompatible_version;
349355
register("seed-multi-region", "multi-region")
350356
}
351357

358+
// expectedToTimeout returns whether the given stmt is likely to timeout due to
359+
// expected edge case behavior.
360+
func expectedToTimeout(t test.Test, stmt string) bool {
361+
// The only known scenario right now (see #157971) is when we have runtime
362+
// assertions enabled AND the query uses a system column that requires MVCC
363+
// decoding.
364+
if !roachtestutil.UsingRuntimeAssertions(t) {
365+
return false
366+
}
367+
for _, sysCol := range []string{
368+
"crdb_internal_mvcc_timestamp",
369+
"crdb_internal_origin_id",
370+
"crdb_internal_origin_timestamp",
371+
} {
372+
if strings.Contains(stmt, sysCol) {
373+
return true
374+
}
375+
}
376+
return false
377+
}
378+
352379
// setupMultiRegionDatabase is used to set up a multi-region database.
353380
func setupMultiRegionDatabase(t test.Test, conn *gosql.DB, rnd *rand.Rand, logStmt func(string)) {
354381
t.Helper()

0 commit comments

Comments
 (0)