From ed128dbbb9cc281d39c7c44c9b44d2ad2eedf8a2 Mon Sep 17 00:00:00 2001 From: Matt Straathof Date: Thu, 7 Mar 2024 09:56:36 -0800 Subject: [PATCH] chore: pr nits, clean up comments, reset resolver state for connection unit tests --- clientconn.go | 2 -- clientconn_parsed_target_test.go | 10 +++++++++- resolver/resolver.go | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/clientconn.go b/clientconn.go index 7bef26f1b185..346fc0e14512 100644 --- a/clientconn.go +++ b/clientconn.go @@ -213,8 +213,6 @@ func NewClient(target string, opts ...DialOption) (conn *ClientConn, err error) // e.g. to use dns resolver, a "dns:///" prefix should be applied to the target. func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *ClientConn, err error) { // At the end of this method, we kick the channel out of idle, rather than waiting for the first rpc. - // The eagerConnect option is used to tell the ClientChannel that DialContext was called to make - // this channel, and hence tries to connect immediately. cc, err := newClient(target, "passthrough", opts...) if err != nil { return nil, err diff --git a/clientconn_parsed_target_test.go b/clientconn_parsed_target_test.go index 95ad64734152..abb80611eae4 100644 --- a/clientconn_parsed_target_test.go +++ b/clientconn_parsed_target_test.go @@ -28,8 +28,8 @@ import ( "github.com/google/go-cmp/cmp" "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/internal" "google.golang.org/grpc/internal/testutils" - "google.golang.org/grpc/resolver" ) @@ -37,7 +37,14 @@ func generateTarget(scheme string, target string) resolver.Target { return resolver.Target{URL: *testutils.MustParseURL(fmt.Sprintf("%s:///%s", scheme, target))} } +// This is here just in case another test calls the SetDefaultScheme method. +func resetInitialResolverState() { + resolver.SetDefaultScheme("passthrough") + internal.UserSetDefaultScheme = false +} + func (s) TestParsedTarget_Success_WithoutCustomDialer(t *testing.T) { + resetInitialResolverState() dialScheme := resolver.GetDefaultScheme() newClientScheme := "dns" tests := []struct { @@ -149,6 +156,7 @@ func (s) TestParsedTarget_Failure_WithoutCustomDialer(t *testing.T) { } func (s) TestParsedTarget_WithCustomDialer(t *testing.T) { + resetInitialResolverState() defScheme := resolver.GetDefaultScheme() tests := []struct { target string diff --git a/resolver/resolver.go b/resolver/resolver.go index ccd84d5c9758..202854511b81 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -64,7 +64,7 @@ func Get(scheme string) Builder { } // SetDefaultScheme sets the default scheme that will be used. The default -// scheme is "passthrough". +// scheme is initially set to "passthrough". // // NOTE: this function must only be called during initialization time (i.e. in // an init() function), and is not thread-safe. The scheme set last overrides