Skip to content

Commit

Permalink
balancer: Enforce embedding the SubConn interface in implementations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
arjan-bal authored Nov 5, 2024
1 parent 2de6df9 commit 43ee172
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions balancer/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 force implementers embed
// this interface, allowing gRPC to add methods without breaking users.
enforceEmbedding()
}

// NewSubConnOptions contains options to create new SubConn.
Expand Down
1 change: 1 addition & 0 deletions balancer/base/balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (c *testClientConn) NewSubConn(addrs []resolver.Address, opts balancer.NewS
func (c *testClientConn) UpdateState(balancer.State) {}

type testSubConn struct {
balancer.SubConn
updateState func(balancer.SubConnState)
}

Expand Down
1 change: 1 addition & 0 deletions balancer_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ func (ccb *ccBalancerWrapper) Target() string {
// acBalancerWrapper is a wrapper on top of ac for balancers.
// It implements balancer.SubConn interface.
type acBalancerWrapper struct {
balancer.SubConn
ac *addrConn // read-only
ccb *ccBalancerWrapper // read-only
stateListener func(balancer.SubConnState)
Expand Down
1 change: 1 addition & 0 deletions internal/testutils/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

// TestSubConn implements the SubConn interface, to be used in tests.
type TestSubConn struct {
balancer.SubConn
tcc *BalancerClientConn // the CC that owns this SubConn
id string
ConnectCh chan struct{}
Expand Down

0 comments on commit 43ee172

Please sign in to comment.