Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Oct 16, 2017
1 parent a3f4d22 commit c9c016c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
30 changes: 2 additions & 28 deletions balancer/roundrobin/roundrobin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import (
"google.golang.org/grpc/test/leakcheck"
)

var rr = balancer.Get("roundrobin")

type testServer struct {
testpb.TestServiceServer
}
Expand Down Expand Up @@ -100,10 +102,6 @@ func TestOneBackend(t *testing.T) {
}
defer test.cleanup()

rr := balancer.Get("roundrobin")
if rr == nil {
t.Fatalf("got nil when trying to get roundrobin balancer builder")
}
cc, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithInsecure(), grpc.WithBalancerBuilder(rr))
if err != nil {
t.Fatalf("failed to dial: %v", err)
Expand Down Expand Up @@ -136,10 +134,6 @@ func TestBackendsRoundRobin(t *testing.T) {
}
defer test.cleanup()

rr := balancer.Get("roundrobin")
if rr == nil {
t.Fatalf("got nil when trying to get roundrobin balancer builder")
}
cc, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithInsecure(), grpc.WithBalancerBuilder(rr))
if err != nil {
t.Fatalf("failed to dial: %v", err)
Expand Down Expand Up @@ -199,10 +193,6 @@ func TestAddressesRemoved(t *testing.T) {
}
defer test.cleanup()

rr := balancer.Get("roundrobin")
if rr == nil {
t.Fatalf("got nil when trying to get roundrobin balancer builder")
}
cc, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithInsecure(), grpc.WithBalancerBuilder(rr))
if err != nil {
t.Fatalf("failed to dial: %v", err)
Expand Down Expand Up @@ -245,10 +235,6 @@ func TestCloseWithPendingRPC(t *testing.T) {
}
defer test.cleanup()

rr := balancer.Get("roundrobin")
if rr == nil {
t.Fatalf("got nil when trying to get roundrobin balancer builder")
}
cc, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithInsecure(), grpc.WithBalancerBuilder(rr))
if err != nil {
t.Fatalf("failed to dial: %v", err)
Expand Down Expand Up @@ -283,10 +269,6 @@ func TestNewAddressWhileBlocking(t *testing.T) {
}
defer test.cleanup()

rr := balancer.Get("roundrobin")
if rr == nil {
t.Fatalf("got nil when trying to get roundrobin balancer builder")
}
cc, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithInsecure(), grpc.WithBalancerBuilder(rr))
if err != nil {
t.Fatalf("failed to dial: %v", err)
Expand Down Expand Up @@ -336,10 +318,6 @@ func TestOneServerDown(t *testing.T) {
}
defer test.cleanup()

rr := balancer.Get("roundrobin")
if rr == nil {
t.Fatalf("got nil when trying to get roundrobin balancer builder")
}
cc, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithInsecure(), grpc.WithBalancerBuilder(rr))
if err != nil {
t.Fatalf("failed to dial: %v", err)
Expand Down Expand Up @@ -433,10 +411,6 @@ func TestAllServersDown(t *testing.T) {
}
defer test.cleanup()

rr := balancer.Get("roundrobin")
if rr == nil {
t.Fatalf("got nil when trying to get roundrobin balancer builder")
}
cc, err := grpc.Dial(r.Scheme()+":///test.server", grpc.WithInsecure(), grpc.WithBalancerBuilder(rr))
if err != nil {
t.Fatalf("failed to dial: %v", err)
Expand Down
17 changes: 14 additions & 3 deletions balancer_switching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,25 @@ func checkPickFirst(cc *ClientConn, servers []*server) error {
reply string
err error
)
// The second RPC should succeed with the first server.
connected := false
for i := 0; i < 1000; i++ {
if err = Invoke(context.Background(), "/foo/bar", &req, &reply, cc); err != nil && ErrorDesc(err) == servers[0].port {
return nil
connected = true
break
}
time.Sleep(time.Millisecond)
}
return fmt.Errorf("EmptyCall() = _, %v, want _, %v", err, servers[0].port)
if !connected {
return fmt.Errorf("EmptyCall() = _, %v, want _, %v", err, servers[0].port)
}
// The following RPCs should all succeed with the first server.
for i := 0; i < 3; i++ {
err = Invoke(context.Background(), "/foo/bar", &req, &reply, cc)
if ErrorDesc(err) != servers[0].port {
return fmt.Errorf("Index %d: want peer %v, got peer %v", i, servers[0].port, err)
}
}
return nil
}

func checkRoundRobin(cc *ClientConn, servers []*server) error {
Expand Down
7 changes: 3 additions & 4 deletions clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,15 +623,14 @@ func (cc *ClientConn) handleResolvedAddrs(addrs []resolver.Address, err error) {
// switchBalancer starts the switching from current balancer to the balancer with name.
func (cc *ClientConn) switchBalancer(name string) {
cc.mu.Lock()
defer cc.mu.Unlock()
if cc.conns == nil {
cc.mu.Unlock()
return
}
defer cc.mu.Unlock()
grpclog.Infof("ClientConn switching balancer to %q", name)

if cc.customBalancer {
grpclog.Infoln("failed to switch balancer because custom balancer was set")
grpclog.Infoln("ignoring service config balancer configuration: WithBalancer DialOption used instead")
return
}

Expand Down Expand Up @@ -659,10 +658,10 @@ func (cc *ClientConn) handleSubConnStateChange(sc balancer.SubConn, s connectivi
cc.mu.Unlock()
return
}
defer cc.mu.Unlock()
// TODO(bar switching) send updates to all balancer wrappers when balancer
// gracefully switching is supported.
cc.balancerWrapper.handleSubConnStateChange(sc, s)
cc.mu.Unlock()
}

// newAddrConn creates an addrConn for addrs and adds it to cc.conns.
Expand Down

0 comments on commit c9c016c

Please sign in to comment.