MCPcopy
hub / github.com/grpc/grpc-go / TestGRPCLB_BalancerDisconnects

Method TestGRPCLB_BalancerDisconnects

balancer/grpclb/grpclb_test.go:714–783  ·  view source on GitHub ↗

TestGRPCLB_BalancerDisconnects tests the case where the remote balancer in use disconnects. The test verifies that grpclb connects to the next remote balancer address specified in attributes, and RPCs get routed to the backends returned by the new balancer.

(t *testing.T)

Source from the content-addressed store, hash-verified

712// balancer address specified in attributes, and RPCs get routed to the backends
713// returned by the new balancer.
714func (s) TestGRPCLB_BalancerDisconnects(t *testing.T) {
715 var (
716 tests []*testServers
717 lbs []*grpc.Server
718 )
719 for i := 0; i < 2; i++ {
720 tss, cleanup, err := startBackendsAndRemoteLoadBalancer(t, 1, "", nil)
721 if err != nil {
722 t.Fatalf("failed to create new load balancer: %v", err)
723 }
724 defer cleanup()
725
726 tss.ls.sls <- &lbpb.ServerList{
727 Servers: []*lbpb.Server{
728 {
729 IpAddress: tss.beIPs[0].AsSlice(),
730 Port: int32(tss.bePorts[0]),
731 LoadBalanceToken: lbToken,
732 },
733 },
734 }
735
736 tests = append(tests, tss)
737 lbs = append(lbs, tss.lb)
738 }
739
740 // Configure the manual resolver with an initial state containing a service
741 // config with grpclb as the load balancing policy and the remote balancer
742 // addresses specified via attributes.
743 r := manual.NewBuilderWithScheme("whatever")
744 s := &grpclbstate.State{
745 BalancerAddresses: []resolver.Address{
746 {
747 Addr: tests[0].lbAddr,
748 ServerName: lbServerName,
749 },
750 {
751 Addr: tests[1].lbAddr,
752 ServerName: lbServerName,
753 },
754 },
755 }
756 rs := grpclbstate.Set(resolver.State{ServiceConfig: internal.ParseServiceConfig.(func(string) *serviceconfig.ParseResult)(grpclbConfig)}, s)
757 r.InitialState(rs)
758
759 dopts := []grpc.DialOption{
760 grpc.WithResolvers(r),
761 grpc.WithTransportCredentials(&serverNameCheckCreds{}),
762 grpc.WithContextDialer(fakeNameDialer),
763 }
764 cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...)
765 if err != nil {
766 t.Fatalf("Failed to create a client for the backend %v", err)
767 }
768 defer cc.Close()
769 testC := testgrpc.NewTestServiceClient(cc)
770
771 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)

Callers

nothing calls this directly

Calls 15

NewBuilderWithSchemeFunction · 0.92
WithResolversFunction · 0.92
WithTransportCredentialsFunction · 0.92
WithContextDialerFunction · 0.92
NewClientFunction · 0.92
CheckRoundRobinRPCsFunction · 0.92
InitialStateMethod · 0.80
FatalfMethod · 0.65
SetMethod · 0.65
SchemeMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected