TestGRPCLB_Basic tests the basic case of a channel being configured with grpclb as the load balancing policy.
(t *testing.T)
| 413 | // TestGRPCLB_Basic tests the basic case of a channel being configured with |
| 414 | // grpclb as the load balancing policy. |
| 415 | func (s) TestGRPCLB_Basic(t *testing.T) { |
| 416 | tss, cleanup, err := startBackendsAndRemoteLoadBalancer(t, 1, testUserAgent, nil) |
| 417 | if err != nil { |
| 418 | t.Fatalf("failed to create new load balancer: %v", err) |
| 419 | } |
| 420 | defer cleanup() |
| 421 | |
| 422 | // Push the test backend address to the remote balancer. |
| 423 | tss.ls.sls <- &lbpb.ServerList{ |
| 424 | Servers: []*lbpb.Server{ |
| 425 | { |
| 426 | IpAddress: tss.beIPs[0].AsSlice(), |
| 427 | Port: int32(tss.bePorts[0]), |
| 428 | LoadBalanceToken: lbToken, |
| 429 | }, |
| 430 | }, |
| 431 | } |
| 432 | |
| 433 | // Configure the manual resolver with an initial state containing a service |
| 434 | // config with grpclb as the load balancing policy and the remote balancer |
| 435 | // address specified via attributes. |
| 436 | r := manual.NewBuilderWithScheme("whatever") |
| 437 | s := &grpclbstate.State{ |
| 438 | BalancerAddresses: []resolver.Address{ |
| 439 | { |
| 440 | Addr: tss.lbAddr, |
| 441 | ServerName: lbServerName, |
| 442 | }, |
| 443 | }, |
| 444 | } |
| 445 | rs := grpclbstate.Set(resolver.State{ServiceConfig: internal.ParseServiceConfig.(func(string) *serviceconfig.ParseResult)(grpclbConfig)}, s) |
| 446 | r.InitialState(rs) |
| 447 | |
| 448 | // Connect to the test backend. |
| 449 | dopts := []grpc.DialOption{ |
| 450 | grpc.WithResolvers(r), |
| 451 | grpc.WithTransportCredentials(&serverNameCheckCreds{}), |
| 452 | grpc.WithContextDialer(fakeNameDialer), |
| 453 | grpc.WithUserAgent(testUserAgent), |
| 454 | } |
| 455 | cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...) |
| 456 | if err != nil { |
| 457 | t.Fatalf("Failed to create a client for the backend %v", err) |
| 458 | } |
| 459 | defer cc.Close() |
| 460 | |
| 461 | // Make one successful RPC. |
| 462 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 463 | defer cancel() |
| 464 | testC := testgrpc.NewTestServiceClient(cc) |
| 465 | if _, err := testC.EmptyCall(ctx, &testpb.Empty{}); err != nil { |
| 466 | t.Fatalf("%v.EmptyCall(_, _) = _, %v, want _, <nil>", testC, err) |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | // TestGRPCLB_Weighted tests weighted roundrobin. The remote balancer is |
| 471 | // configured to send a response with duplicate backend addresses (to simulate |
nothing calls this directly
no test coverage detected