Skip to content

Commit

Permalink
chore: pr nits, clean up comments, reset resolver state for connectio…
Browse files Browse the repository at this point in the history
…n unit tests
  • Loading branch information
bruuuuuuuce committed Mar 7, 2024
1 parent 6ad5013 commit ed128db
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 0 additions & 2 deletions clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion clientconn_parsed_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,23 @@ 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"
)

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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ed128db

Please sign in to comment.