Skip to content

Commit

Permalink
gracefulswitch, stub: remove last UpdateSubConnState references (#6533)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley authored Aug 10, 2023
1 parent 4900699 commit 68704f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
29 changes: 16 additions & 13 deletions internal/balancer/gracefulswitch/gracefulswitch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ func (mb1 *mockBalancer) ResolverError(err error) {
}

func (mb1 *mockBalancer) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {
mb1.scStateCh.Send(subConnWithState{sc: sc, state: state})
panic(fmt.Sprintf("UpdateSubConnState(%v, %+v) called unexpectedly", sc, state))
}

func (mb1 *mockBalancer) Close() {
Expand Down Expand Up @@ -951,7 +951,9 @@ func (mb1 *mockBalancer) updateState(state balancer.State) {

func (mb1 *mockBalancer) newSubConn(addrs []resolver.Address, opts balancer.NewSubConnOptions) (sc balancer.SubConn, err error) {
if opts.StateListener == nil {
opts.StateListener = func(state balancer.SubConnState) { mb1.UpdateSubConnState(sc, state) }
opts.StateListener = func(state balancer.SubConnState) {
mb1.scStateCh.Send(subConnWithState{sc: sc, state: state})
}
}
defer func() {
if sc != nil {
Expand Down Expand Up @@ -994,13 +996,13 @@ func (verifyBalancerBuilder) Name() string {
return verifyBalName
}

// verifyBalancer is a balancer that verifies that after a Close() call, an
// updateSubConnState() call never happens.
// verifyBalancer is a balancer that verifies that after a Close() call, a
// StateListener() call never happens.
type verifyBalancer struct {
closed *grpcsync.Event
// Hold onto the ClientConn wrapper to communicate with it.
cc balancer.ClientConn
// To fail the test if UpdateSubConnState gets called after Close().
// To fail the test if StateListener gets called after Close().
t *testing.T
}

Expand All @@ -1011,9 +1013,7 @@ func (vb *verifyBalancer) UpdateClientConnState(ccs balancer.ClientConnState) er
func (vb *verifyBalancer) ResolverError(err error) {}

func (vb *verifyBalancer) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {
if vb.closed.HasFired() {
vb.t.Fatal("UpdateSubConnState was called after Close(), which breaks the balancer API")
}
panic(fmt.Sprintf("UpdateSubConnState(%v, %+v) called unexpectedly", sc, state))
}

func (vb *verifyBalancer) Close() {
Expand All @@ -1022,7 +1022,11 @@ func (vb *verifyBalancer) Close() {

func (vb *verifyBalancer) newSubConn(addrs []resolver.Address, opts balancer.NewSubConnOptions) (sc balancer.SubConn, err error) {
if opts.StateListener == nil {
opts.StateListener = func(state balancer.SubConnState) { vb.UpdateSubConnState(sc, state) }
opts.StateListener = func(state balancer.SubConnState) {
if vb.closed.HasFired() {
vb.t.Fatalf("StateListener(%+v) was called after Close(), which breaks the balancer API", state)
}
}
}
defer func() { sc.Connect() }()
return vb.cc.NewSubConn(addrs, opts)
Expand Down Expand Up @@ -1064,7 +1068,9 @@ func (bcb *buildCallbackBal) UpdateClientConnState(ccs balancer.ClientConnState)

func (bcb *buildCallbackBal) ResolverError(err error) {}

func (bcb *buildCallbackBal) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {}
func (bcb *buildCallbackBal) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState) {
panic(fmt.Sprintf("UpdateSubConnState(%v, %+v) called unexpectedly", sc, state))
}

func (bcb *buildCallbackBal) Close() {
bcb.closeCh.Send(struct{}{})
Expand All @@ -1075,9 +1081,6 @@ func (bcb *buildCallbackBal) updateState(state balancer.State) {
}

func (bcb *buildCallbackBal) newSubConn(addrs []resolver.Address, opts balancer.NewSubConnOptions) (sc balancer.SubConn, err error) {
if opts.StateListener == nil {
opts.StateListener = func(state balancer.SubConnState) { bcb.UpdateSubConnState(sc, state) }
}
defer func() {
if sc != nil {
sc.Connect()
Expand Down
6 changes: 2 additions & 4 deletions internal/balancer/stub/stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package stub

import (
"encoding/json"
"fmt"

"google.golang.org/grpc/balancer"
"google.golang.org/grpc/serviceconfig"
Expand All @@ -38,7 +39,6 @@ type BalancerFuncs struct {

UpdateClientConnState func(*BalancerData, balancer.ClientConnState) error
ResolverError func(*BalancerData, error)
UpdateSubConnState func(*BalancerData, balancer.SubConn, balancer.SubConnState)
Close func(*BalancerData)
ExitIdle func(*BalancerData)
}
Expand Down Expand Up @@ -72,9 +72,7 @@ func (b *bal) ResolverError(e error) {
}

func (b *bal) UpdateSubConnState(sc balancer.SubConn, scs balancer.SubConnState) {
if b.bf.UpdateSubConnState != nil {
b.bf.UpdateSubConnState(b.bd, sc, scs)
}
panic(fmt.Sprintf("UpdateSubConnState(%v, %+v) called unexpectedly", sc, scs))
}

func (b *bal) Close() {
Expand Down

0 comments on commit 68704f8

Please sign in to comment.