TestGRPCLB_DropRequest tests grpclb support for dropping requests based on configuration received from the remote balancer. TODO: Rewrite this test to verify drop behavior using the ClientStats.CallsFinishedWithDrop field instead.
(t *testing.T)
| 547 | // TODO: Rewrite this test to verify drop behavior using the |
| 548 | // ClientStats.CallsFinishedWithDrop field instead. |
| 549 | func (s) TestGRPCLB_DropRequest(t *testing.T) { |
| 550 | tss, cleanup, err := startBackendsAndRemoteLoadBalancer(t, 2, "", nil) |
| 551 | if err != nil { |
| 552 | t.Fatalf("failed to create new load balancer: %v", err) |
| 553 | } |
| 554 | defer cleanup() |
| 555 | tss.ls.sls <- &lbpb.ServerList{ |
| 556 | Servers: []*lbpb.Server{{ |
| 557 | IpAddress: tss.beIPs[0].AsSlice(), |
| 558 | Port: int32(tss.bePorts[0]), |
| 559 | LoadBalanceToken: lbToken, |
| 560 | Drop: false, |
| 561 | }, { |
| 562 | IpAddress: tss.beIPs[1].AsSlice(), |
| 563 | Port: int32(tss.bePorts[1]), |
| 564 | LoadBalanceToken: lbToken, |
| 565 | Drop: false, |
| 566 | }, { |
| 567 | Drop: true, |
| 568 | }}, |
| 569 | } |
| 570 | |
| 571 | // Configure the manual resolver with an initial state containing a service |
| 572 | // config with grpclb as the load balancing policy and the remote balancer |
| 573 | // address specified via attributes. |
| 574 | r := manual.NewBuilderWithScheme("whatever") |
| 575 | s := &grpclbstate.State{ |
| 576 | BalancerAddresses: []resolver.Address{ |
| 577 | { |
| 578 | Addr: tss.lbAddr, |
| 579 | ServerName: lbServerName, |
| 580 | }, |
| 581 | }, |
| 582 | } |
| 583 | rs := grpclbstate.Set(resolver.State{ServiceConfig: internal.ParseServiceConfig.(func(string) *serviceconfig.ParseResult)(grpclbConfig)}, s) |
| 584 | r.InitialState(rs) |
| 585 | |
| 586 | // Connect to test backends. |
| 587 | dopts := []grpc.DialOption{ |
| 588 | grpc.WithResolvers(r), |
| 589 | grpc.WithTransportCredentials(&serverNameCheckCreds{}), |
| 590 | grpc.WithContextDialer(fakeNameDialer), |
| 591 | } |
| 592 | cc, err := grpc.NewClient(r.Scheme()+":///"+beServerName, dopts...) |
| 593 | if err != nil { |
| 594 | t.Fatalf("Failed to create a client for the backend %v", err) |
| 595 | } |
| 596 | defer cc.Close() |
| 597 | testC := testgrpc.NewTestServiceClient(cc) |
| 598 | |
| 599 | var ( |
| 600 | i int |
| 601 | p peer.Peer |
| 602 | ) |
| 603 | const ( |
| 604 | // Poll to wait for something to happen. Total timeout 1 second. Sleep 1 |
| 605 | // ms each loop, and do at most 1000 loops. |
| 606 | sleepEachLoop = time.Millisecond |
nothing calls this directly
no test coverage detected