Skip to content
Open
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
10 changes: 10 additions & 0 deletions transport/grpc/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,16 @@ func processAndValidateOpts(opts []option.ClientOption) (*internal.DialSettings,
return &o, nil
}

// UserConfiguredGRPCConnPoolSize processes the client options and returns the configured
// gRPC connection pool size. It returns an error if the provided options are invalid.
func UserConfiguredGRPCConnPoolSize(opts ...option.ClientOption) (int, error) {
o, err := processAndValidateOpts(opts)
if err != nil {
return 0, err
}
return o.GRPCConnPoolSize, nil
}

type connPoolOption struct{ ConnPool }

// WithConnPool returns a ClientOption that specifies the ConnPool
Expand Down
41 changes: 41 additions & 0 deletions transport/grpc/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/google/go-cmp/cmp"
"golang.org/x/oauth2/google"
"google.golang.org/api/internal"
"google.golang.org/api/option"
"google.golang.org/grpc"
)

Expand Down Expand Up @@ -258,3 +259,43 @@ func TestGRPCAPIKey_GetRequestMetadata(t *testing.T) {
}
}
}

func TestConfiguredGRPCConnPoolSize(t *testing.T) {
tests := []struct {
name string
opts []option.ClientOption
wantSize int
wantErr bool
}{
{
name: "No options",
opts: []option.ClientOption{},
wantSize: 0,
wantErr: false,
},
{
name: "WithGRPCConnectionPool(5)",
opts: []option.ClientOption{option.WithGRPCConnectionPool(5)},
wantSize: 5,
wantErr: false,
},
{
name: "WithGRPCConnectionPool(0)",
opts: []option.ClientOption{option.WithGRPCConnectionPool(0)},
wantSize: 0,
wantErr: false,
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
gotSize, err := UserConfiguredGRPCConnPoolSize(tc.opts...)
if (err != nil) != tc.wantErr {
t.Errorf("ConfiguredGRPCConnPoolSize() returned error: %v, wantErr: %v", err, tc.wantErr)
}
if !tc.wantErr && gotSize != tc.wantSize {
t.Errorf("ConfiguredGRPCConnPoolSize() = %d, want %d", gotSize, tc.wantSize)
}
})
}
}