Skip to content

Commit

Permalink
Merge pull request #124574 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-23.2-124564

release-23.2: sqlccl: de-flake TestActiveCancelSession
  • Loading branch information
yuzefovich authored May 23, 2024
2 parents c2582be + 01ca48c commit 59ec42d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/ccl/testccl/sqlccl/run_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/sql/sqltestutils"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
Expand Down Expand Up @@ -205,6 +206,27 @@ func testCancelSession(t *testing.T, hasActiveSession bool) {
_, err = conn1.ExecContext(ctx, "SELECT pg_sleep(1000000)")
errChan <- err
}()
// Block until the query goroutine was spun up and began
// executing the query - this is needed to avoid a race between
// canceling the session before vs after 'pg_sleep' query begins
// (the former would result in an unexpected error message).
testutils.SucceedsSoon(t, func() error {
row := conn2.QueryRowContext(ctx, `
SELECT count(*) FROM [SHOW CLUSTER QUERIES] WHERE query LIKE '%pg_sleep%'
AND query NOT LIKE '%SHOW CLUSTER QUERIES%'
;`)
var count int
if err = row.Scan(&count); err != nil {
t.Fatal(err)
}
if count == 1 {
return nil
}
if count > 1 {
t.Fatalf("unexpectedly found %d pg_sleep queries", count)
}
return errors.New("pg_sleep query hasn't started yet")
})
}

// Cancel the session on node 1.
Expand Down

0 comments on commit 59ec42d

Please sign in to comment.