Skip to content

Commit

Permalink
sql: Fix TestCancelQueriesRace
Browse files Browse the repository at this point in the history
TestCancelQueriesRace attempts to run two query cancellations
at the same time in order to reproduce potential data race.
However, it makes an invalid assumption that both query cancellations
will always succeed which is not true. This PR updates the check
to ensure that at least one of the query cancellations is successful.

Epic: none
Fixes: #95718
Release note: none
  • Loading branch information
rimadeodhar committed Jul 7, 2023
1 parent f704150 commit 1cdfc5f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/sql/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1341,14 +1341,18 @@ func TestCancelQueriesRace(t *testing.T) {
_, _ = sqlDB.ExecContext(ctx, `SELECT pg_sleep(10)`)
close(waiter)
}()
_, err := sqlDB.ExecContext(ctx, `CANCEL QUERIES (
_, err1 := sqlDB.ExecContext(ctx, `CANCEL QUERIES (
SELECT query_id FROM [SHOW QUERIES] WHERE query LIKE 'SELECT pg_sleep%'
)`)
require.NoError(t, err)
_, err = sqlDB.ExecContext(ctx, `CANCEL QUERIES (

_, err2 := sqlDB.ExecContext(ctx, `CANCEL QUERIES (
SELECT query_id FROM [SHOW QUERIES] WHERE query LIKE 'SELECT pg_sleep%'
)`)
require.NoError(t, err)
// At least one query cancellation is expected to succeed.
require.Truef(
t,
err1 == nil || err2 == nil,
"Both query cancellations failed with errors: %v and %v", err1, err2)

cancel()
<-waiter
Expand Down

0 comments on commit 1cdfc5f

Please sign in to comment.