Skip to content

Commit

Permalink
Merge #42805
Browse files Browse the repository at this point in the history
42805: roachtest: force timeout differently in sqlsmith test r=yuzefovich a=yuzefovich

Previously, sqlsmith roachtest would use a context with timeout to
force the query cancellation. However, CockroachDB currently doesn't
implement pgwire cancellation protocol, so canceling a context would not
actually propagate to the database. Instead, we will use
'statement_timeout' session variable to specify the timeout.

Addresses: #42212.
Addresses: #42217.

Release note: None

Co-authored-by: Yahor Yuzefovich <[email protected]>
  • Loading branch information
craig[bot] and yuzefovich committed Nov 27, 2019
2 parents 91b92a6 + 94bb64b commit d1e5758
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pkg/cmd/roachtest/sqlsmith.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ func registerSQLSmith(r *testRegistry) {
}
logStmt(setup)

const timeout = time.Minute
setStmtTimeout := fmt.Sprintf("SET statement_timeout='%s';", timeout.String())
t.Status("setting statement_timeout")
c.l.Printf("statement timeout:\n%s", setStmtTimeout)
if _, err := conn.Exec(setStmtTimeout); err != nil {
t.Fatal(err)
}
logStmt(setStmtTimeout)

smither, err := sqlsmith.NewSmither(conn, rng, setting.Options...)
if err != nil {
t.Fatal(err)
Expand All @@ -125,11 +134,14 @@ func registerSQLSmith(r *testRegistry) {
stmt := smither.Generate()
err := func() error {
done := make(chan error, 1)
const timeout = time.Minute
go func(ctx context.Context) {
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
_, err := conn.ExecContext(ctx, stmt)
go func(context.Context) {
// At the moment, CockroachDB doesn't support pgwire query
// cancellation which is needed for correct handling of context
// cancellation, so instead of using a context with timeout, we opt
// in for using CRDB's 'statement_timeout'.
// TODO(yuzefovich): once #41335 is implemented, go back to using a
// context with timeout.
_, err := conn.Exec(stmt)
if err != nil {
logStmt(stmt)
}
Expand Down

0 comments on commit d1e5758

Please sign in to comment.