-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
cleanup: replace dial with newclient #7967
base: master
Are you sure you want to change the base?
cleanup: replace dial with newclient #7967
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #7967 +/- ##
==========================================
+ Coverage 82.17% 82.26% +0.09%
==========================================
Files 381 383 +2
Lines 38546 38776 +230
==========================================
+ Hits 31676 31900 +224
+ Misses 5560 5555 -5
- Partials 1310 1321 +11 |
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, stateRecordingBalancerName))) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer client.Close() | ||
|
||
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.
There is a call to testutils.StayConnected
below, do we need to call connect
here? Please consider this every time you replace Dial with NewClient across all PRs.
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.
getting the below error without connect() call
timed out waiting for state 0 (CONNECTING) in flow [CONNECTING READY IDLE CONNECTING]
test/gracefulstop_test.go
Outdated
ctx, dialCancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||
defer dialCancel() | ||
cc, err := grpc.DialContext(ctx, "", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(d)) | ||
cc, err := grpc.NewClient("localhost:0", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(d)) |
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.
Use passthrough instead of changing the hostname. I've mentioned the usage of custom dialers before.
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
} | ||
cc.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.
Instead of calling cc.Connect
here make the callers of setupForSecurityTests
call it only if needed.
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
} | ||
cc.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.
Instead of calling cc.Connect
here make the callers of setupWithManagementServerAndListener
call it only if needed.
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.
Similar comment for other setup functions.
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 cc1, err = grpc.NewClient(lis1.Addr().String(), grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials())); err != nil { | ||
t.Fatal("Failed to create clientConn to a server in \"not-serving\" state") |
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.
This is not the same assertion as before. You need to make an RPC and check that it fails.
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
Please ensure tests pass before raising the PR. |
Yeah sure, but before pushing the changes verified locally, there were no issues. |
@@ -313,9 +315,9 @@ func (s) TestCloseConnectionWhenServerPrefaceNotReceived(t *testing.T) { | |||
break | |||
} | |||
}() | |||
client, err := Dial(lis.Addr().String(), WithTransportCredentials(insecure.NewCredentials()), withMinConnectDeadline(func() time.Duration { return time.Millisecond * 500 })) |
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.
The test should be renamed now, replacing Dial
with NewClient
. Same change throughout.
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.
Yeah, I'm about to ask you that question, Thanks for the clarification.
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
// SwitchBalancer before NewAddress. There was no balancer created, this | ||
// makes sure we don't call close on nil balancerWrapper. | ||
sc := internal.ParseServiceConfig.(func(string) *serviceconfig.ParseResult) | ||
r.InitialState(resolver.State{ServiceConfig: sc(`{"loadBalancingPolicy": "round_robin"}`)}) // This should not panic. | ||
|
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.
This is changing the test behaviour. NewClient will not create a balancer unless RPC is made or connect is called. So "switching" balancer is essentially a no-op. Instead we should do the following:
- Create NewClient
- Call cc.Connect()
- Call r.UpdateState() with the new LB config.
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
|
||
cc, err := Dial(r.Scheme()+":///test.server", WithTransportCredentials(insecure.NewCredentials()), WithResolvers(r)) | ||
sc := internal.ParseServiceConfig.(func(string) *serviceconfig.ParseResult) | ||
go r.InitialState(resolver.State{ServiceConfig: sc(`{"loadBalancingPolicy": "round_robin"}`)}) // This should not panic. | ||
cc, err := NewClient(r.Scheme()+":///test.server", WithTransportCredentials(insecure.NewCredentials()), WithResolvers(r)) | ||
if err != nil { | ||
t.Fatalf("failed to dial: %v", err) | ||
t.Fatalf("Failed to create a client for server: %v", err) | ||
} | ||
// Send a new service config while closing the ClientConn. | ||
go cc.Close() | ||
go r.UpdateState(resolver.State{ServiceConfig: parseCfg(r, `{"loadBalancingPolicy": "round_robin"}`)}) // This should not panic. |
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.
This changes the scenario that was being tested. Instead of using r.InitialState
keep the UpdateState
calls. Just call cc.Connect()
after creating the new client/
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
cc, err := Dial(r.Scheme()+":///test.server", WithTransportCredentials(insecure.NewCredentials()), WithResolvers(r)) | ||
// This make sure we don't create addrConn with empty address list. | ||
r.InitialState(resolver.State{}) // This should not panic. | ||
|
||
cc, err := NewClient(r.Scheme()+":///test.server", WithTransportCredentials(insecure.NewCredentials()), WithResolvers(r)) | ||
if err != nil { | ||
t.Fatalf("failed to dial: %v", err) | ||
t.Fatalf("Failed to create a client for server: %v", err) | ||
} |
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.
The resolver is not created because NewClient is lazy. So the panic can't happen. Please consider what the test is trying to do and ensure the behviour is the same while making changes.
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
@arjan-bal Kindly please suggest the below queries:
|
Partially address: #7049
RELEASE NOTES: None