-
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 all commits
65f9bbe
578671c
c83de4b
714bd88
b060b0c
98695b5
1a53f2b
889cf0c
66a1b3c
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 |
---|---|---|
|
@@ -27,6 +27,7 @@ import ( | |
"time" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"google.golang.org/grpc/connectivity" | ||
"google.golang.org/grpc/credentials/insecure" | ||
"google.golang.org/grpc/internal" | ||
"google.golang.org/grpc/internal/testutils" | ||
|
@@ -195,10 +196,15 @@ func (s) TestParsedTarget_Failure_WithoutCustomDialer(t *testing.T) { | |
|
||
for _, target := range targets { | ||
t.Run(target, func(t *testing.T) { | ||
if cc, err := Dial(target, WithTransportCredentials(insecure.NewCredentials())); err == nil { | ||
defer cc.Close() | ||
t.Fatalf("Dial(%q) succeeded cc.parsedTarget = %+v, expected to fail", target, cc.parsedTarget) | ||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) | ||
defer cancel() | ||
cc, err := NewClient(target, WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
t.Fatalf("grpc.NewClient(%q) failed: %v, expected to succeed", target, err) | ||
} | ||
defer cc.Close() | ||
cc.Connect() | ||
testutils.AwaitState(ctx, t, cc, connectivity.Idle) | ||
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. This is pretty much a no-op since the channel starts in |
||
}) | ||
} | ||
} | ||
|
@@ -273,11 +279,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()), withDefaultScheme(defScheme), WithContextDialer(dialer)) | ||
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 don't think we should override the default scheme to 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 your feedback, I used withDefaultScheme only in the specific tests where it’s needed, as suggested by Arjan. For checking the default NewClient behavior with a custom dialer, I’m not overriding the scheme. If you’d like a separate test specifically for NewClient's default behavior, let me know and I can add it. |
||
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 |
---|---|---|
|
@@ -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 { | ||
|
@@ -85,12 +85,12 @@ func (s) TestResolverCaseSensitivity(t *testing.T) { | |
// 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())) | ||
cc, err = NewClient(target, WithContextDialer(customDialer), withDefaultScheme("passthrough"), 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 { | ||
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. Can we revert this change? It seems to be a no-op since the target variable has the same value. |
||
cc.Close() | ||
t.Fatalf("Dialer got address %q; wanted %q", got, want) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are changing the check condition here , is it intentional? If it is , the error message isn't correct. We are checking
err!=nil
which meansNewClient
failed and the error message saysNewClient succeeded
which is not right.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done