-
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
balancer: Enforce embedding the SubConn interface in implementations #7758
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #7758 +/- ##
==========================================
+ Coverage 81.71% 81.81% +0.09%
==========================================
Files 374 371 -3
Lines 38166 37700 -466
==========================================
- Hits 31188 30844 -344
+ Misses 5699 5563 -136
- Partials 1279 1293 +14
|
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 a potential breaking change. I suspect it would only break tests (doing mocking?), but it's possible to break actual users. That's OK, we just need to be careful to document the change and also take care when importing the code internally.
balancer/balancer.go
Outdated
@@ -155,6 +155,9 @@ type SubConn interface { | |||
// indicate the shutdown operation. This may be delivered before | |||
// in-progress RPCs are complete and the actual connection is closed. | |||
Shutdown() | |||
// enforceEmbedding is an unexported method to enforce implementers embed |
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.
"...to force implementers to embed..." or "to enforce that implementers embed".
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.
Grammar fixed.
@dfawley , I checked the internal usages and found that adding a private method will break code generated using GoMock, e.g: https://github.com/GoogleCloudPlatform/grpc-gcp-go/blob/d2bc599b72aeef2d85143b234ca7d602ae7f4302/grpcgcp/mocks/mock_balancer.go#L116-L119 Due to the private method, the generated mock no longer implements the Users could manually edit the generated mocks to embed |
Hmm.. at least internally, mocking is not recommended for Go. I'm not sure about the external world though. Do you have any experience using mocking frameworks and know what is more commonly used and whether they generate code differently wherein the generated code embeds the mocked interface? (some google searching didn't yield anything useful)
I guess this is no worse if you didn't use mocking and didn't embed, but chose to implement the methods to satisfy the interface. |
@@ -32,6 +32,7 @@ import ( | |||
|
|||
// TestSubConn implements the SubConn interface, to be used in tests. | |||
type TestSubConn struct { | |||
balancer.SubConn |
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.
Funny that we ourselves didn't embed the interface in our tests.
Probably not if they're generated, unless they're also checked in, and then...maybe. How many instances of this exist? Is it feasible to fix all the ones that we're (indirectly) responsible for? |
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.
LGTM, but we need to wait to check this in until all the internal dependencies are resolved.
…enforce-embedding
The PR in grpc-gcp-go is merged: GoogleCloudPlatform/grpc-gcp-go#89 |
Presently, the doc comment on the
balancer.SubConn
interface mentions that external implementers should embed thebalancer.SubConn
interface, however, this is not enforced at compilation time:This PR adds an unexported method on the interface to add a compile time check for enforcing the requirement.
Release notes transferred to new PR that reworks this slightly.
RELEASE NOTES: None