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 #7975

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

Conversation

janardhanvissa
Copy link
Contributor

@janardhanvissa janardhanvissa commented Dec 31, 2024

Partially address: #7049

RELEASE NOTES: None

test/xds/xds_client_federation_test.go Outdated Show resolved Hide resolved
test/xds/xds_client_federation_test.go Show resolved Hide resolved
test/local_creds_test.go Outdated Show resolved Hide resolved
test/clientconn_state_transition_test.go Outdated Show resolved Hide resolved
test/xds/xds_client_federation_test.go Outdated Show resolved Hide resolved
test/xds/xds_client_federation_test.go Show resolved Hide resolved
test/xds/xds_client_federation_test.go Outdated Show resolved Hide resolved
test/local_creds_test.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Dec 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.95%. Comparing base (724f450) to head (ab5f146).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7975      +/-   ##
==========================================
- Coverage   82.05%   81.95%   -0.10%     
==========================================
  Files         381      381              
  Lines       38539    38539              
==========================================
- Hits        31622    31585      -37     
- Misses       5602     5627      +25     
- Partials     1315     1327      +12     

see 25 files with indirect coverage changes

test/local_creds_test.go Outdated Show resolved Hide resolved
test/xds/xds_client_federation_test.go Outdated Show resolved Hide resolved
if err == nil || !strings.Contains(err.Error(), wantErr) {
t.Fatalf("grpc.Dial(%q) returned %v, want: %s", target, err, wantErr)
t.Fatalf("Expected error containing %q, got: %v", wantErr, 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 log message should contain the function that was called.

Suggested change
t.Fatalf("Expected error containing %q, got: %v", wantErr, err)
t.Fatalf("EmptyCall(_, _) = _, %v; want _, %q", wantErr, err)

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

Copy link
Contributor

Choose a reason for hiding this comment

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

The order of wantErr and err is inverted. err should come before wantErr.

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

clientconn.go Outdated
Comment on lines 166 to 170
// validation for the google-c2p scheme.
if cc.parsedTarget.URL.Scheme == "google-c2p" && cc.parsedTarget.URL.Host != "" {
return nil, fmt.Errorf("google-c2p URI scheme does not support authorities")
}

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 how you get the test to pass :b. The validation is done by the resolver and not the gRPC channel. The gRPC channel is generic and doesn't care about the google-c2p scheme.

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

@@ -315,15 +315,15 @@ func (s) TestBuildXDS(t *testing.T) {
func (s) TestBuildFailsWhenCalledWithAuthority(t *testing.T) {
useCleanUniverseDomain(t)
uri := "google-c2p://an-authority/resource"
cc, err := grpc.Dial(uri, grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(uri, grpc.WithTransportCredentials(insecure.NewCredentials()))
defer func() {
if cc != nil {
cc.Close()
}
}()
wantErr := "google-c2p URI scheme does not support authorities"
if err == nil || !strings.Contains(err.Error(), wantErr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

NewClient is lazy, so the the resolver will not be built until and rpc is made of cc.Connect is called. You would need to create a test service client, call client.EmptyCall and check for the error string in the returned error. This is very similar to the fix made in the federation test.

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 5449 to 5453
lis, err := net.Listen("tcp", "localhost:0")
if err != nil {
t.Fatalf("Failed to listen: %v", err)
}
defer lis.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems unnecessary. You can just pass the target URI as "passthrough:///", no need to create a listener and get it's address.

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

}
defer cc.Close()

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.

You can avoid using cc.Connect here by replacing the r.UpdateState below with r.InitialState.

}
defer cc.Close()

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.

You can avoid using cc.Connect here by replacing the r.UpdateState below with r.InitialState.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The resolver is getting as nil after updating to r.InitialState before creating a client conn.

}
defer cc.Close()

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.

You can avoid using cc.Connect here by replacing the r.UpdateState below with r.InitialState.

Copy link
Contributor Author

@janardhanvissa janardhanvissa Jan 5, 2025

Choose a reason for hiding this comment

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

@arjan-bal If we do like replacing r.UpdateState to r.InitialState, first we should ensure that the manual.Resolver.CC must be set grpc.NewClient before calling parseServiceConfig. So, we cannot update to r.InitialState before creating a NewClient.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can use internal.ParseConfig to avoid depending on manual.Resolver.CC.

}
defer cc.Close()

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.

You can avoid using cc.Connect here by replacing the r.UpdateState below with r.InitialState. Please check other places where the same change can be made.

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

Successfully merging this pull request may close these issues.

3 participants