Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
130442: sqlproxyccl: add ServerlessOnly test helper r=jeffswenson a=jeffswenson

This change updates every sql proxy test so that it calls the new ServerlessOnly test helper. Serverless supports fewer versions than traditional CRDB. Once a version of CRDB no longer supports Serverless, the ServerlessOnly helper will be updated to skip the tests. The purpose of this helper is to avoid unnecessary test triaging and limit the number of versions test fixes must be backported to.

Most of this change was generated by the following commands:
```
fastmod -F 'AfterTest(t)()' 'AfterTest(t)(); testutilsccl.ServerlessOnly()'
go fmt ./...
goimports -w .
```

Part of: cockroachdb#130441

Co-authored-by: Jeff Swenson <[email protected]>
  • Loading branch information
craig[bot] and jeffswenson committed Sep 13, 2024
2 parents 40b449a + 557a62f commit c0777f6
Show file tree
Hide file tree
Showing 36 changed files with 227 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/ccl/sqlproxyccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ go_test(
"//pkg/ccl/sqlproxyccl/tenant",
"//pkg/ccl/sqlproxyccl/tenantdirsvr",
"//pkg/ccl/sqlproxyccl/throttler",
"//pkg/ccl/testutilsccl",
"//pkg/roachpb",
"//pkg/security/certnames",
"//pkg/security/securityassets",
Expand Down
1 change: 1 addition & 0 deletions pkg/ccl/sqlproxyccl/acl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ go_test(
deps = [
"//pkg/ccl/sqlproxyccl/tenant",
"//pkg/ccl/sqlproxyccl/tenantdirsvr",
"//pkg/ccl/testutilsccl",
"//pkg/roachpb",
"//pkg/testutils",
"//pkg/util/leaktest",
Expand Down
2 changes: 2 additions & 0 deletions pkg/ccl/sqlproxyccl/acl/cidr_ranges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/ccl/sqlproxyccl/acl"
"github.com/cockroachdb/cockroach/pkg/ccl/sqlproxyccl/tenant"
"github.com/cockroachdb/cockroach/pkg/ccl/testutilsccl"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/errors"
Expand All @@ -22,6 +23,7 @@ import (

func TestCIDRRanges(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)
ctx := context.Background()

tenantID := roachpb.MustMakeTenantID(42)
Expand Down
21 changes: 21 additions & 0 deletions pkg/ccl/sqlproxyccl/acl/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"testing"
"time"

"github.com/cockroachdb/cockroach/pkg/ccl/testutilsccl"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
Expand All @@ -30,6 +31,9 @@ import (

func TestDenyListFileParsing(t *testing.T) {
t.Run("test custom marshal code", func(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

cases := []struct {
t DenyType
expected string
Expand All @@ -45,6 +49,9 @@ func TestDenyListFileParsing(t *testing.T) {
})

t.Run("test DenyType custom unmarshal code", func(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

cases := []struct {
raw string
expected DenyType
Expand All @@ -67,6 +74,8 @@ func TestDenyListFileParsing(t *testing.T) {

t.Run("end to end testing of DenylistFile parsing", func(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

expirationTimeString := "2021-01-01T15:20:39Z"
expirationTime := time.Date(2021, 1, 1, 15, 20, 39, 0, time.UTC)

Expand Down Expand Up @@ -130,6 +139,9 @@ denylist:
})

t.Run("test Ser/De of File", func(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

file := DenylistFile{
Seq: 72,
Denylist: []*DenyEntry{
Expand All @@ -156,6 +168,7 @@ denylist:

func TestDenylistLogic(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

startTime := time.Date(2021, 1, 1, 15, 20, 39, 0, time.UTC)
longExpirationTimeString := "2030-01-01T15:30:39Z"
Expand Down Expand Up @@ -314,6 +327,9 @@ func parseIPNet(cidr string) *net.IPNet {
func TestAllowListFileParsing(t *testing.T) {

t.Run("test AllowEntry custom unmarshal code", func(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

cases := []struct {
raw string
expected AllowEntry
Expand Down Expand Up @@ -367,6 +383,7 @@ func TestAllowListFileParsing(t *testing.T) {

t.Run("end to end testing of AllowlistFile parsing", func(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

testCases := []struct {
input string
Expand Down Expand Up @@ -441,6 +458,7 @@ allowlist:

func TestAllowlistLogic(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

type allowIOSpec struct {
connection ConnectionTags
Expand Down Expand Up @@ -491,6 +509,9 @@ allowlist:
}

func TestParsingErrorHandling(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

// Use cancel to prevent leaked goroutines from file watches.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
3 changes: 3 additions & 0 deletions pkg/ccl/sqlproxyccl/acl/private_endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/ccl/sqlproxyccl/acl"
"github.com/cockroachdb/cockroach/pkg/ccl/sqlproxyccl/tenant"
"github.com/cockroachdb/cockroach/pkg/ccl/testutilsccl"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/errors"
Expand All @@ -25,6 +26,7 @@ import (

func TestPrivateEndpoints(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)
ctx := context.Background()

makeConn := func(endpoint string) acl.ConnectionTags {
Expand Down Expand Up @@ -97,6 +99,7 @@ func TestPrivateEndpoints(t *testing.T) {

func TestFindPrivateEndpointID(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

newHeader := func(t *testing.T, tlvs []proxyproto.TLV) *proxyproto.Header {
t.Helper()
Expand Down
2 changes: 2 additions & 0 deletions pkg/ccl/sqlproxyccl/acl/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/ccl/sqlproxyccl/tenant"
"github.com/cockroachdb/cockroach/pkg/ccl/sqlproxyccl/tenantdirsvr"
"github.com/cockroachdb/cockroach/pkg/ccl/testutilsccl"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
Expand Down Expand Up @@ -68,6 +69,7 @@ func cidrRanges(fn lookupTenantFunc) *CIDRRanges {

func TestACLWatcher(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

ctx := context.Background()
stopper := stop.NewStopper()
Expand Down
8 changes: 8 additions & 0 deletions pkg/ccl/sqlproxyccl/authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"testing"

"github.com/cockroachdb/cockroach/pkg/ccl/sqlproxyccl/throttler"
"github.com/cockroachdb/cockroach/pkg/ccl/testutilsccl"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/jackc/pgproto3/v2"
Expand All @@ -26,6 +27,7 @@ var nilThrottleHook = func(state throttler.AttemptStatus) error {

func TestAuthenticateOK(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

cli, srv := net.Pipe()
be := pgproto3.NewBackend(pgproto3.NewChunkReader(srv), srv)
Expand Down Expand Up @@ -55,6 +57,7 @@ func TestAuthenticateOK(t *testing.T) {

func TestAuthenticateClearText(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

cli, srv := net.Pipe()
be := pgproto3.NewBackend(pgproto3.NewChunkReader(srv), srv)
Expand Down Expand Up @@ -98,6 +101,7 @@ func TestAuthenticateClearText(t *testing.T) {

func TestAuthenticateThrottled(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

server := func(t *testing.T, be *pgproto3.Backend) {
require.NoError(t, be.Send(&pgproto3.AuthenticationCleartextPassword{}))
Expand Down Expand Up @@ -153,6 +157,7 @@ func TestAuthenticateThrottled(t *testing.T) {

func TestErrorFollowingAuthenticateNotThrottled(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

server := func(t *testing.T, be *pgproto3.Backend) {
require.NoError(t, be.Send(&pgproto3.AuthenticationCleartextPassword{}))
Expand Down Expand Up @@ -208,6 +213,7 @@ func TestErrorFollowingAuthenticateNotThrottled(t *testing.T) {

func TestAuthenticateError(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

cli, srv := net.Pipe()
be := pgproto3.NewBackend(pgproto3.NewChunkReader(srv), srv)
Expand All @@ -228,6 +234,7 @@ func TestAuthenticateError(t *testing.T) {

func TestAuthenticateUnexpectedMessage(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

cli, srv := net.Pipe()
be := pgproto3.NewBackend(pgproto3.NewChunkReader(srv), srv)
Expand All @@ -250,6 +257,7 @@ func TestAuthenticateUnexpectedMessage(t *testing.T) {

func TestReadTokenAuthResult(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

t.Run("unexpected message", func(t *testing.T) {
cli, srv := net.Pipe()
Expand Down
6 changes: 6 additions & 0 deletions pkg/ccl/sqlproxyccl/backend_dialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/ccl/testutilsccl"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/security/certnames"
"github.com/cockroachdb/cockroach/pkg/security/securitytest"
Expand All @@ -33,6 +34,7 @@ import (

func TestBackendDialTLSInsecure(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)
defer log.Scope(t).Close(t)

ctx := context.Background()
Expand All @@ -49,6 +51,7 @@ func TestBackendDialTLSInsecure(t *testing.T) {

func TestBackendDialBlackhole(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)
defer log.Scope(t).Close(t)

listener, err := net.Listen("tcp", "127.0.0.1:0")
Expand All @@ -74,6 +77,7 @@ func TestBackendDialBlackhole(t *testing.T) {

func TestBackendDialTLS(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)
defer log.Scope(t).Close(t)

startupMsg := &pgproto3.StartupMessage{ProtocolVersion: pgproto3.ProtocolVersionNumber}
Expand Down Expand Up @@ -172,6 +176,7 @@ func (n *closeCounter) CloseCount() int {

func TestCloseOnCancelCleanupBeforeCancel(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)
defer log.Scope(t).Close(t)

conn := &closeCounter{}
Expand All @@ -186,6 +191,7 @@ func TestCloseOnCancelCleanupBeforeCancel(t *testing.T) {

func TestCloseOnCancelCancelBeforeCleanup(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)
defer log.Scope(t).Close(t)

conn := &closeCounter{}
Expand Down
1 change: 1 addition & 0 deletions pkg/ccl/sqlproxyccl/balancer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ go_test(
embed = [":balancer"],
deps = [
"//pkg/ccl/sqlproxyccl/tenant",
"//pkg/ccl/testutilsccl",
"//pkg/roachpb",
"//pkg/testutils",
"//pkg/util/leaktest",
Expand Down
2 changes: 2 additions & 0 deletions pkg/ccl/sqlproxyccl/balancer/assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"context"
"testing"

"github.com/cockroachdb/cockroach/pkg/ccl/testutilsccl"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/stop"
Expand All @@ -20,6 +21,7 @@ import (

func TestServerAssignment(t *testing.T) {
defer leaktest.AfterTest(t)()
testutilsccl.ServerlessOnly(t)

ctx := context.Background()
stopper := stop.NewStopper()
Expand Down
Loading

0 comments on commit c0777f6

Please sign in to comment.