-
Couldn't load subscription status.
- 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
Changes from 5 commits
65f9bbe
578671c
c83de4b
714bd88
b060b0c
98695b5
1a53f2b
889cf0c
66a1b3c
f1c77ee
115b4f7
f4de7e2
02196ff
40a938e
2ced611
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. 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've raised a PR with the proposed change: #8643. @vinothkumarr227 you can leave this test unchanged in this PR, I'll update the test at part of #8643. 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. After investigating, I confirmed that RPCs already fail with the correct error message. The connection is attempted when the stream creation function calls exitIdle, as seen here: Lines 180 to 186 in 2d92271
Therefore, no changes are needed to propagate the error. While cc.Connect itself cannot return an error due to its signature, any resolver build failure is correctly surfaced to the user during the next RPC. This test can be changes as follows to create a new stream and validate the error. cc, err := NewClient(target, WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("NewClient(%q) failed: %v", target, err)
}
defer cc.Close()
wantErrSubstr := "failed to exit idle mode"
if _, err := cc.NewStream(ctx, &StreamDesc{}, "/my.service.v1.MyService/UnaryCall"); err == nil {
t.Fatalf("NewStream() succeeded with target = %q, cc.parsedTarget = %+v, expected to fail", target, cc.parsedTarget)
} else if !strings.Contains(err.Error(), wantErrSubstr) {
t.Fatalf("NewStream() with target = %q returned unexpected error: got %v, want substring %q", target, err, wantErrSubstr)
}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. Thanks for the suggestion. I have modified the code changes accordingly 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. In the team meeting, we discussed this and decided that we should keep the origin test that uses 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. Done |
||||||||||||||||||
| "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 |
|---|---|---|
|
|
@@ -29,12 +29,12 @@ import ( | |
| ) | ||
|
|
||
| func (s) TestAddGlobalDialOptions(t *testing.T) { | ||
| // Ensure the Dial fails without credentials | ||
| if _, err := Dial("fake"); err == nil { | ||
| t.Fatalf("Dialing without a credential did not fail") | ||
| // Ensure the NewClient fails without credentials | ||
| if _, err := NewClient("dns:///fake"); err == nil { | ||
| t.Fatalf("grpc.NewClient without a credential did not fail") | ||
|
||
| } else { | ||
| if !strings.Contains(err.Error(), "no transport security set") { | ||
| t.Fatalf("Dialing failed with unexpected error: %v", err) | ||
| t.Fatalf("grpc.NewClient failed with unexpected error: %v", err) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -48,9 +48,9 @@ func (s) TestAddGlobalDialOptions(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| // Ensure the Dial passes with the extra dial options | ||
| if cc, err := Dial("fake"); err != nil { | ||
| t.Fatalf("Dialing with insecure credential failed: %v", err) | ||
| // Ensure the NewClient passes with the extra dial options | ||
| if cc, err := NewClient("dns:///fake"); err != nil { | ||
arjan-bal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| t.Fatalf("grpc.NewClient with insecure credential failed: %v", err) | ||
| } else { | ||
| cc.Close() | ||
| } | ||
|
|
@@ -71,8 +71,8 @@ func (s) TestDisableGlobalOptions(t *testing.T) { | |
| // due to the global dial options with credentials not being picked up due | ||
| // to global options being disabled. | ||
| noTSecStr := "no transport security set" | ||
| if _, err := Dial("fake", internal.DisableGlobalDialOptions.(func() DialOption)()); !strings.Contains(fmt.Sprint(err), noTSecStr) { | ||
| t.Fatalf("Dialing received unexpected error: %v, want error containing \"%v\"", err, noTSecStr) | ||
| if _, err := NewClient("dns:///fake", internal.DisableGlobalDialOptions.(func() DialOption)()); !strings.Contains(fmt.Sprint(err), noTSecStr) { | ||
| t.Fatalf("grpc.NewClient received unexpected error: %v, want error containing \"%v\"", err, noTSecStr) | ||
arjan-bal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -95,11 +95,11 @@ func (s) TestGlobalPerTargetDialOption(t *testing.T) { | |
| defer internal.ClearGlobalPerTargetDialOptions() | ||
| noTSecStr := "no transport security set" | ||
| if _, err := NewClient("dns:///fake"); !strings.Contains(fmt.Sprint(err), noTSecStr) { | ||
| t.Fatalf("Dialing received unexpected error: %v, want error containing \"%v\"", err, noTSecStr) | ||
| t.Fatalf("grpc.NewClient received unexpected error: %v, want error containing \"%v\"", err, noTSecStr) | ||
arjan-bal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| cc, err := NewClient("passthrough:///nice") | ||
| if err != nil { | ||
| t.Fatalf("Dialing with insecure credentials failed: %v", err) | ||
| t.Fatalf("grpc.NewClient with insecure credentials failed: %v", err) | ||
| } | ||
| cc.Close() | ||
| } | ||
|
|
@@ -135,9 +135,9 @@ func (s) TestJoinDialOption(t *testing.T) { | |
| const maxRecvSize = 998765 | ||
| const initialWindowSize = 100 | ||
| jdo := newJoinDialOption(WithTransportCredentials(insecure.NewCredentials()), WithReadBufferSize(maxRecvSize), WithInitialWindowSize(initialWindowSize)) | ||
| cc, err := Dial("fake", jdo) | ||
| cc, err := NewClient("dns:///fake", jdo) | ||
| if err != nil { | ||
| t.Fatalf("Dialing with insecure credentials failed: %v", err) | ||
| t.Fatalf("grpc.NewClient with insecure credentials failed: %v", err) | ||
| } | ||
| defer cc.Close() | ||
| if cc.dopts.copts.ReadBufferSize != maxRecvSize { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.