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

Method TestGRPCLB_FallBackWithNoServerAddress

balancer/grpclb/grpclb_test.go:963–1063  ·  view source on GitHub ↗

TestGRPCLB_FallBackWithNoServerAddress tests the fallback case where no backend addresses are returned by the remote balancer.

(t *testing.T)

Source from the content-addressed store, hash-verified

961// TestGRPCLB_FallBackWithNoServerAddress tests the fallback case where no
962// backend addresses are returned by the remote balancer.
963func (s) TestGRPCLB_FallBackWithNoServerAddress(t *testing.T) {
964 resolveNowCh := testutils.NewChannel()
965 r := manual.NewBuilderWithScheme("whatever")
966 r.ResolveNowCallback = func(resolver.ResolveNowOptions) {
967 ctx, cancel := context.WithTimeout(context.Background(), defaultTestShortTimeout)
968 defer cancel()
969 if err := resolveNowCh.SendContext(ctx, nil); err != nil {
970 t.Error("timeout when attempting to send on resolverNowCh")
971 }
972 }
973
974 // Start a remote balancer and a backend. Don't push the backend address to
975 // the remote balancer yet.
976 tss, cleanup, err := startBackendsAndRemoteLoadBalancer(t, 1, "", nil)
977 if err != nil {
978 t.Fatalf("failed to create new load balancer: %v", err)
979 }
980 defer cleanup()
981 sl := &lbpb.ServerList{
982 Servers: []*lbpb.Server{
983 {
984 IpAddress: tss.beIPs[0].AsSlice(),
985 Port: int32(tss.bePorts[0]),
986 LoadBalanceToken: lbToken,
987 },
988 },
989 }
990
991 // Start a standalone backend for fallback.
992 beLis, err := net.Listen("tcp", "localhost:0")
993 if err != nil {
994 t.Fatalf("Failed to listen %v", err)
995 }
996 defer beLis.Close()
997 standaloneBEs := startBackends(t, beServerName, true, beLis)
998 defer stopBackends(standaloneBEs)
999
1000 dopts := []grpc.DialOption{
1001 grpc.WithResolvers(r),
1002 grpc.WithTransportCredentials(&serverNameCheckCreds{}),
1003 grpc.WithContextDialer(fakeNameDialer),
1004 }
1005 cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...)
1006 if err != nil {
1007 t.Fatalf("Failed to create a client for the backend %v", err)
1008 }
1009 defer cc.Close()
1010 cc.Connect()
1011 testC := testgrpc.NewTestServiceClient(cc)
1012
1013 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
1014 defer cancel()
1015 for i := 0; i < 2; i++ {
1016 // Send an update with only backend address. grpclb should enter
1017 // fallback and use the fallback backend.
1018 r.UpdateState(resolver.State{
1019 Addresses: []resolver.Address{{Addr: beLis.Addr().String()}},
1020 ServiceConfig: r.CC().ParseServiceConfig(grpclbConfig),

Callers

nothing calls this directly

Calls 15

SendContextMethod · 0.95
ReceiveMethod · 0.95
EmptyCallMethod · 0.95
NewChannelFunction · 0.92
NewBuilderWithSchemeFunction · 0.92
WithResolversFunction · 0.92
WithTransportCredentialsFunction · 0.92
WithContextDialerFunction · 0.92
NewClientFunction · 0.92
WaitForReadyFunction · 0.92
PeerFunction · 0.92
CheckRoundRobinRPCsFunction · 0.92

Tested by

no test coverage detected