Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-23.1: sql/tests: deflake TestErrorDuringExtendedProtocolCommit and TestCancelQueriesRace #104672

Merged
merged 2 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/sql/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1201,12 +1201,14 @@ func TestCancelQueriesRace(t *testing.T) {
_, _ = sqlDB.ExecContext(ctx, `SELECT pg_sleep(10)`)
close(waiter)
}()
_, _ = sqlDB.ExecContext(ctx, `CANCEL QUERIES (
_, err := sqlDB.ExecContext(ctx, `CANCEL QUERIES (
SELECT query_id FROM [SHOW QUERIES] WHERE query LIKE 'SELECT pg_sleep%'
)`)
_, _ = sqlDB.ExecContext(ctx, `CANCEL QUERIES (
require.NoError(t, err)
_, err = sqlDB.ExecContext(ctx, `CANCEL QUERIES (
SELECT query_id FROM [SHOW QUERIES] WHERE query LIKE 'SELECT pg_sleep%'
)`)
require.NoError(t, err)

cancel()
<-waiter
Expand Down
1 change: 0 additions & 1 deletion pkg/sql/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ go_test(
"//pkg/util/syncutil",
"//pkg/util/timeutil",
"//pkg/util/tracing",
"//pkg/util/tracing/tracingpb",
"//pkg/util/uuid",
"@com_github_cockroachdb_cockroach_go_v2//crdb",
"@com_github_cockroachdb_cockroach_go_v2//crdb/crdbpgx",
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/tests/autocommit_extended_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"errors"
"net/url"
"strings"
"sync/atomic"
"testing"

"github.com/cockroachdb/cockroach/pkg/base"
Expand All @@ -27,7 +28,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
"github.com/cockroachdb/cockroach/pkg/util/tracing"
"github.com/cockroachdb/cockroach/pkg/util/tracing/tracingpb"
"github.com/jackc/pgx/v4"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -158,14 +158,14 @@ func TestErrorDuringExtendedProtocolCommit(t *testing.T) {
var db *gosql.DB

var shouldErrorOnAutoCommit syncutil.AtomicBool
var traceID tracingpb.TraceID
var traceID atomic.Uint64
params, _ := CreateTestServerParams()
params.Knobs.SQLExecutor = &sql.ExecutorTestingKnobs{
DisableAutoCommitDuringExec: true,
BeforeExecute: func(ctx context.Context, stmt string, descriptors *descs.Collection) {
if strings.Contains(stmt, "SELECT 'cat'") {
shouldErrorOnAutoCommit.Set(true)
traceID = tracing.SpanFromContext(ctx).TraceID()
traceID.Store(uint64(tracing.SpanFromContext(ctx).TraceID()))
}
},
BeforeAutoCommit: func(ctx context.Context, stmt string) error {
Expand All @@ -174,7 +174,7 @@ func TestErrorDuringExtendedProtocolCommit(t *testing.T) {
// saw when executing our test query. This is so we know that this
// autocommit corresponds to our test qyery rather than an internal
// query.
if traceID == tracing.SpanFromContext(ctx).TraceID() {
if traceID.Load() == uint64(tracing.SpanFromContext(ctx).TraceID()) {
shouldErrorOnAutoCommit.Set(false)
return errors.New("injected error")
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/leaktest/leaktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func interestingGoroutines() map[int64]string {
strings.Contains(stack, "github.com/jackc/pgconn.(*PgConn).asyncClose.func1") ||
// Ignore pgconn which creates a goroutine to watch context cancellation.
strings.Contains(stack, "github.com/jackc/pgconn/internal/ctxwatch.(*ContextWatcher).Watch.func1") ||
// Ignore pq goroutine that watches for context cancellation.
strings.Contains(stack, "github.com/lib/pq.(*conn).watchCancel") ||
// Seems to be gccgo specific.
(runtime.Compiler == "gccgo" && strings.Contains(stack, "testing.T.Parallel")) ||
// Ignore intentionally long-running logging goroutines that live for the
Expand Down