-
Notifications
You must be signed in to change notification settings - Fork 4.6k
cleanup: replace dial with newclient #8602
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
65f9bbe
578671c
c83de4b
714bd88
b060b0c
98695b5
1a53f2b
889cf0c
66a1b3c
f1c77ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -62,74 +62,63 @@ func init() { resolver.Register(testResolverForParser{}) } | |||
func (s) TestParsedTarget_Success_WithoutCustomDialer(t *testing.T) { | ||||
tests := []struct { | ||||
target string | ||||
wantDialParse resolver.Target | ||||
wantNewClientParse resolver.Target | ||||
wantCustomParse resolver.Target | ||||
}{ | ||||
// No scheme is specified. | ||||
{ | ||||
target: "://a/b", | ||||
wantDialParse: generateTarget("passthrough:///://a/b"), | ||||
wantNewClientParse: generateTarget("dns:///://a/b"), | ||||
wantCustomParse: generateTarget("testresolverforparser:///://a/b"), | ||||
}, | ||||
{ | ||||
target: "a//b", | ||||
wantDialParse: generateTarget("passthrough:///a//b"), | ||||
wantNewClientParse: generateTarget("dns:///a//b"), | ||||
wantCustomParse: generateTarget("testresolverforparser:///a//b"), | ||||
}, | ||||
|
||||
// An unregistered scheme is specified. | ||||
{ | ||||
target: "a:///", | ||||
wantDialParse: generateTarget("passthrough:///a:///"), | ||||
wantNewClientParse: generateTarget("dns:///a:///"), | ||||
wantCustomParse: generateTarget("testresolverforparser:///a:///"), | ||||
}, | ||||
{ | ||||
target: "a:b", | ||||
wantDialParse: generateTarget("passthrough:///a:b"), | ||||
wantNewClientParse: generateTarget("dns:///a:b"), | ||||
wantCustomParse: generateTarget("testresolverforparser:///a:b"), | ||||
}, | ||||
|
||||
// A registered scheme is specified. | ||||
{ | ||||
target: "dns://a.server.com/google.com", | ||||
wantDialParse: generateTarget("dns://a.server.com/google.com"), | ||||
wantNewClientParse: generateTarget("dns://a.server.com/google.com"), | ||||
wantCustomParse: generateTarget("dns://a.server.com/google.com"), | ||||
}, | ||||
{ | ||||
target: "unix-abstract:/ a///://::!@#$%25^&*()b", | ||||
wantDialParse: generateTarget("unix-abstract:/ a///://::!@#$%25^&*()b"), | ||||
wantNewClientParse: generateTarget("unix-abstract:/ a///://::!@#$%25^&*()b"), | ||||
wantCustomParse: generateTarget("unix-abstract:/ a///://::!@#$%25^&*()b"), | ||||
}, | ||||
{ | ||||
target: "unix-abstract:passthrough:abc", | ||||
wantDialParse: generateTarget("unix-abstract:passthrough:abc"), | ||||
wantNewClientParse: generateTarget("unix-abstract:passthrough:abc"), | ||||
wantCustomParse: generateTarget("unix-abstract:passthrough:abc"), | ||||
}, | ||||
{ | ||||
target: "passthrough:///unix:///a/b/c", | ||||
wantDialParse: generateTarget("passthrough:///unix:///a/b/c"), | ||||
wantNewClientParse: generateTarget("passthrough:///unix:///a/b/c"), | ||||
wantCustomParse: generateTarget("passthrough:///unix:///a/b/c"), | ||||
}, | ||||
|
||||
// Cases for `scheme:absolute-path`. | ||||
{ | ||||
target: "dns:/a/b/c", | ||||
wantDialParse: generateTarget("dns:/a/b/c"), | ||||
wantNewClientParse: generateTarget("dns:/a/b/c"), | ||||
wantCustomParse: generateTarget("dns:/a/b/c"), | ||||
}, | ||||
{ | ||||
target: "unregistered:/a/b/c", | ||||
wantDialParse: generateTarget("passthrough:///unregistered:/a/b/c"), | ||||
wantNewClientParse: generateTarget("dns:///unregistered:/a/b/c"), | ||||
wantCustomParse: generateTarget("testresolverforparser:///unregistered:/a/b/c"), | ||||
}, | ||||
|
@@ -138,19 +127,9 @@ func (s) TestParsedTarget_Success_WithoutCustomDialer(t *testing.T) { | |||
for _, test := range tests { | ||||
t.Run(test.target, func(t *testing.T) { | ||||
resetInitialResolverState() | ||||
cc, err := Dial(test.target, WithTransportCredentials(insecure.NewCredentials())) | ||||
cc, err := NewClient(test.target, WithTransportCredentials(insecure.NewCredentials())) | ||||
if err != nil { | ||||
t.Fatalf("Dial(%q) failed: %v", test.target, err) | ||||
} | ||||
cc.Close() | ||||
|
||||
if !cmp.Equal(cc.parsedTarget, test.wantDialParse) { | ||||
t.Errorf("cc.parsedTarget for dial target %q = %+v, want %+v", test.target, cc.parsedTarget, test.wantDialParse) | ||||
} | ||||
|
||||
cc, err = NewClient(test.target, WithTransportCredentials(insecure.NewCredentials())) | ||||
if err != nil { | ||||
t.Fatalf("NewClient(%q) failed: %v", test.target, err) | ||||
t.Fatalf("grpc.NewClient(%q) failed: %v", test.target, err) | ||||
} | ||||
cc.Close() | ||||
|
||||
|
@@ -159,19 +138,9 @@ func (s) TestParsedTarget_Success_WithoutCustomDialer(t *testing.T) { | |||
} | ||||
|
||||
resolver.SetDefaultScheme("testresolverforparser") | ||||
cc, err = Dial(test.target, WithTransportCredentials(insecure.NewCredentials())) | ||||
if err != nil { | ||||
t.Fatalf("Dial(%q) failed: %v", test.target, err) | ||||
} | ||||
cc.Close() | ||||
|
||||
if !cmp.Equal(cc.parsedTarget, test.wantCustomParse) { | ||||
t.Errorf("cc.parsedTarget for dial target %q = %+v, want %+v", test.target, cc.parsedTarget, test.wantDialParse) | ||||
} | ||||
|
||||
cc, err = NewClient(test.target, WithTransportCredentials(insecure.NewCredentials())) | ||||
if err != nil { | ||||
t.Fatalf("NewClient(%q) failed: %v", test.target, err) | ||||
t.Fatalf("grpc.NewClient(%q) failed: %v", test.target, err) | ||||
} | ||||
cc.Close() | ||||
|
||||
|
@@ -186,18 +155,14 @@ func (s) TestParsedTarget_Success_WithoutCustomDialer(t *testing.T) { | |||
|
||||
func (s) TestParsedTarget_Failure_WithoutCustomDialer(t *testing.T) { | ||||
targets := []string{ | ||||
"", | ||||
"unix://a/b/c", | ||||
"unix://authority", | ||||
"unix-abstract://authority/a/b/c", | ||||
"unix-abstract://authority", | ||||
Comment on lines
189
to
193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not remove these test cases. Since
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am using Idle because these malformed targets result in zero resolved addresses. The client never attempts a connection, so it stays IDLE and cannot reach TRANSIENT_FAILURE There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an INFO log similar to the following from the unix resolver:
Since this is the only indication that the connection attempt failed (no errors are returned), I think this should be logged as an ERROR. Presently, the method responsible for channelz trace event logging is logging everything at as an INFO log. We could have at accept the severity as an additional param to achieve this. Once this is an error log, we can assert that the error is logged similar to the following. grpc-go/internal/transport/keepalive_test.go Line 401 in 8389ddb
@dfawley do you think we should log the failure to exit idle mode in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two options:
Either way, RPCs will fail with that error message text, and we shouldn't need anything besides INFO (or even V2?) logs. |
||||
"unix:/%a/b/c", | ||||
} | ||||
|
||||
for _, target := range targets { | ||||
t.Run(target, func(t *testing.T) { | ||||
if cc, err := Dial(target, WithTransportCredentials(insecure.NewCredentials())); err == nil { | ||||
if cc, err := NewClient(target, WithTransportCredentials(insecure.NewCredentials())); err == nil { | ||||
defer cc.Close() | ||||
t.Fatalf("Dial(%q) succeeded cc.parsedTarget = %+v, expected to fail", target, cc.parsedTarget) | ||||
t.Fatalf("grpc.NewClient(%q) succeeded cc.parsedTarget = %+v, expected to fail", target, cc.parsedTarget) | ||||
} | ||||
}) | ||||
} | ||||
|
@@ -234,7 +199,7 @@ func (s) TestParsedTarget_WithCustomDialer(t *testing.T) { | |||
wantDialerAddress: "127.0.0.1:50051", | ||||
}, | ||||
{ | ||||
target: ":///127.0.0.1:50051", | ||||
target: "passthrough:///:///127.0.0.1:50051", | ||||
wantParsed: resolver.Target{URL: *testutils.MustParseURL(fmt.Sprintf("%s:///%s", defScheme, ":///127.0.0.1:50051"))}, | ||||
wantDialerAddress: ":///127.0.0.1:50051", | ||||
}, | ||||
|
@@ -244,17 +209,17 @@ func (s) TestParsedTarget_WithCustomDialer(t *testing.T) { | |||
wantDialerAddress: "127.0.0.1:50051", | ||||
}, | ||||
{ | ||||
target: "://authority/127.0.0.1:50051", | ||||
target: "passthrough:///://authority/127.0.0.1:50051", | ||||
wantParsed: resolver.Target{URL: *testutils.MustParseURL(fmt.Sprintf("%s:///%s", defScheme, "://authority/127.0.0.1:50051"))}, | ||||
wantDialerAddress: "://authority/127.0.0.1:50051", | ||||
}, | ||||
{ | ||||
target: "/unix/socket/address", | ||||
target: "passthrough:////unix/socket/address", | ||||
wantParsed: resolver.Target{URL: *testutils.MustParseURL(fmt.Sprintf("%s:///%s", defScheme, "/unix/socket/address"))}, | ||||
wantDialerAddress: "/unix/socket/address", | ||||
}, | ||||
{ | ||||
target: "", | ||||
target: "passthrough:///", | ||||
arjan-bal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
wantParsed: resolver.Target{URL: *testutils.MustParseURL(fmt.Sprintf("%s:///%s", defScheme, ""))}, | ||||
wantDialerAddress: "", | ||||
}, | ||||
|
@@ -273,11 +238,12 @@ func (s) TestParsedTarget_WithCustomDialer(t *testing.T) { | |||
return nil, errors.New("dialer error") | ||||
} | ||||
|
||||
cc, err := Dial(test.target, WithTransportCredentials(insecure.NewCredentials()), WithContextDialer(dialer)) | ||||
cc, err := NewClient(test.target, WithTransportCredentials(insecure.NewCredentials()), WithContextDialer(dialer)) | ||||
if err != nil { | ||||
t.Fatalf("Dial(%q) failed: %v", test.target, err) | ||||
t.Fatalf("grpc.NewClient(%q) failed: %v", test.target, err) | ||||
} | ||||
defer cc.Close() | ||||
cc.Connect() | ||||
|
||||
select { | ||||
case addr := <-addrCh: | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,11 +97,12 @@ func (s) TestDialWithTimeout(t *testing.T) { | |
|
||
r := manual.NewBuilderWithScheme("whatever") | ||
r.InitialState(resolver.State{Addresses: []resolver.Address{lisAddr}}) | ||
client, err := Dial(r.Scheme()+":///test.server", WithTransportCredentials(insecure.NewCredentials()), WithResolvers(r), WithTimeout(5*time.Second)) | ||
client, err := NewClient(r.Scheme()+":///test.server", WithTransportCredentials(insecure.NewCredentials()), WithResolvers(r), WithTimeout(5*time.Second)) | ||
arjan-bal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
close(dialDone) | ||
if err != nil { | ||
t.Fatalf("Dial failed. Err: %v", err) | ||
t.Fatalf("grpc.NewClient failed. Err: %v", err) | ||
} | ||
client.Connect() | ||
|
||
defer client.Close() | ||
timeout := time.After(1 * time.Second) | ||
select { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,9 +63,9 @@ func (s) TestResolverCaseSensitivity(t *testing.T) { | |
return nil, fmt.Errorf("not dialing with custom dialer") | ||
} | ||
|
||
cc, err := Dial(target, WithContextDialer(customDialer), WithTransportCredentials(insecure.NewCredentials())) | ||
cc, err := NewClient(target, WithContextDialer(customDialer), WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
t.Fatalf("Unexpected Dial(%q) error: %v", target, err) | ||
t.Fatalf("Unexpected grpc.NewClient(%q) error: %v", target, err) | ||
} | ||
cc.Connect() | ||
if got, want := <-addrCh, "localhost:1234"; got != want { | ||
|
@@ -84,13 +84,13 @@ func (s) TestResolverCaseSensitivity(t *testing.T) { | |
// This should not find the injected resolver due to the case not matching. | ||
// This results in "passthrough" being used with the address as the whole | ||
// target. | ||
target = "caseTest2:///localhost:1234" | ||
cc, err = Dial(target, WithContextDialer(customDialer), WithResolvers(res), WithTransportCredentials(insecure.NewCredentials())) | ||
target = "passthrough:///caseTest2:///localhost:1234" | ||
arjan-bal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
cc, err = NewClient(target, WithContextDialer(customDialer), WithResolvers(res), WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
t.Fatalf("Unexpected Dial(%q) error: %v", target, err) | ||
t.Fatalf("Unexpected grpc.NewClient(%q) error: %v", target, err) | ||
} | ||
cc.Connect() | ||
if got, want := <-addrCh, target; got != want { | ||
if got, want := <-addrCh, "caseTest2:///localhost:1234"; got != want { | ||
|
||
cc.Close() | ||
t.Fatalf("Dialer got address %q; wanted %q", got, want) | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.