-
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
Changes from 14 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 |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
"errors" | ||
"fmt" | ||
"net" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
|
@@ -203,6 +204,34 @@ func (s) TestParsedTarget_Failure_WithoutCustomDialer(t *testing.T) { | |
} | ||
} | ||
|
||
func (s) TestParsedTarget_Failure_WithoutCustomDialer_WithNewClient(t *testing.T) { | ||
targets := []string{ | ||
"", | ||
"unix://a/b/c", | ||
"unix://authority", | ||
"unix-abstract://authority/a/b/c", | ||
"unix-abstract://authority", | ||
} | ||
|
||
for _, target := range targets { | ||
t.Run(target, func(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
cc, err := NewClient(target, WithTransportCredentials(insecure.NewCredentials())) | ||
if err != nil { | ||
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 are changing the check condition here , is it intentional? If it is , the error message isn't correct. We are checking 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 |
||
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) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func (s) TestParsedTarget_WithCustomDialer(t *testing.T) { | ||
resetInitialResolverState() | ||
defScheme := resolver.GetDefaultScheme() | ||
|
@@ -273,11 +302,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: | ||
|
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 have a const
defaultTestTimeout
defined in this package that is also set to10s
. Please use that instead of hardcoding the value here. Thanks.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