Skip to content
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

Open
wants to merge 49 commits into
base: master
Choose a base branch
from

Conversation

janardhanvissa
Copy link
Contributor

Partially address: #7049

RELEASE NOTES: None

Copy link

codecov bot commented Dec 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.26%. Comparing base (f35fb34) to head (e253082).
Report is 17 commits behind head on master.

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     

see 51 files with indirect coverage changes

grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, stateRecordingBalancerName)))
if err != nil {
t.Fatal(err)
}
defer client.Close()

client.Connect()
Copy link
Contributor

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.

Copy link
Contributor Author

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]

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))
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
cc.Connect()
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
cc.Connect()
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +313 to +314
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")
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@arjan-bal
Copy link
Contributor

Please ensure tests pass before raising the PR.

@janardhanvissa
Copy link
Contributor Author

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 }))
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 663 to 667
// 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.

Copy link
Contributor

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:

  1. Create NewClient
  2. Call cc.Connect()
  3. Call r.UpdateState() with the new LB config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 677 to 684

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.
Copy link
Contributor

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/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 691 to 700
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)
}
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@janardhanvissa
Copy link
Contributor Author

@arjan-bal Kindly please suggest the below queries:

  1. Seems like there is some issue in TestClientUpdatesParamsAfterGoAway how to proceed on this. Please suggest this.
  2. Do we need to replace Dial/DialContext with NewClient for the below tests also?
    TestDialContextCancel
    TestDialContextFailFast
    TestDialWaitsForServerSettingsAndFails
    TestWithTimeout
    TestWithTransportCredentialsTLS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants