-
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?
cleanup: replace dial with newclient #8602
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8602 +/- ##
==========================================
+ Coverage 81.86% 82.08% +0.21%
==========================================
Files 415 415
Lines 40694 40711 +17
==========================================
+ Hits 33316 33416 +100
+ Misses 5993 5907 -86
- Partials 1385 1388 +3 🚀 New features to boost your workflow:
|
func (s) TestParsedTarget_Success_WithoutCustomDialer(t *testing.T) { | ||
tests := []struct { | ||
target string | ||
wantDialParse resolver.Target |
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.
Please keep this test param and related assertions. We need to keep tests that test Dial
specifically, since Dial
will be supported for gRPC Go 1.x. We only need to replace Dial
in tests which are not intended to verify the behaviour of Dial
.
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
"", | ||
"unix://a/b/c", | ||
"unix://authority", | ||
"unix-abstract://authority/a/b/c", | ||
"unix-abstract://authority", |
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 should not remove these test cases. Since NewClient
doesn't connect like Dial
, we need to do the following to get an error instead:
- Call cc.Connect()
- Wait for TRANSIENT_FAILURE state using AwaitState. If using this function causes a circular dependency, copy it over to this file, adding a comment that mentioning the reason for the duplication.
- If context times out before TF state, fail the test.
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.
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
clientconn_parsed_target_test.go
Outdated
}, | ||
{ | ||
target: "", | ||
target: "passthrough:///", |
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.
Instead of changing all the test cases, you can instead use the private withDefaultScheme
dial option to change the default scheme from dns
to passthrough
.
Lines 733 to 739 in 8ae3c07
// withDefaultScheme is used to allow Dial to use "passthrough" as the default | |
// name resolver, while NewClient uses "dns" otherwise. | |
func withDefaultScheme(s string) DialOption { | |
return newFuncDialOption(func(o *dialOptions) { | |
o.defaultScheme = s | |
}) | |
} |
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
clientconn_test.go
Outdated
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)) |
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.
Please revert this change. The WithTimeout
dial option is a no-op with NewClient
, see godoc. We should continue to test it with Dial
.
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
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 { |
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.
Why do we need to set the dns
scheme explicitly here? Doesn't NewClient
add it automatically?
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.
Thanks for pointing this out. I have reverted it
resolver_test.go
Outdated
// target. | ||
target = "caseTest2:///localhost:1234" | ||
cc, err = Dial(target, WithContextDialer(customDialer), WithResolvers(res), WithTransportCredentials(insecure.NewCredentials())) | ||
target = "passthrough:///caseTest2:///localhost:1234" |
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.
Why are we adding 2 schemes here? Due to passthrough
, the wrapped resolver created above wouldn't even be called.
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.
No need a two schema here, I reverted it
ctx, cancel := context.WithTimeout(context.Background(), 2*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 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 means NewClient
failed and the error message says NewClient succeeded
which is not right.
} | ||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should override the default scheme to passthrough
with new client because we want to check the behavior of parsed strings with defualt NewClient
function with custom dialer. And the behavior might be different , because dns
resolver also does its own parsing , so the results might be different. Correct me if I have understood incorrectly. But I think we should have a separate test for NewClient's
default parsed address behavior with custom dialer
clientconn_test.go
Outdated
if err != nil { | ||
t.Fatalf("Dial failed. Err: %v", err) | ||
} | ||
client.Connect() |
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.
Why did we add this here? We did not change from Dial
to NewClient
in the test and Dial will connect automatically?
Fixes: #7049
RELEASE NOTES: None