TestDropByCategory verifies that the balancer correctly drops the picks, and that the drops are reported.
(t *testing.T)
| 562 | // TestDropByCategory verifies that the balancer correctly drops the picks, and |
| 563 | // that the drops are reported. |
| 564 | func (s) TestDropByCategory(t *testing.T) { |
| 565 | // Create an xDS management server that serves ADS and LRS requests. |
| 566 | mgmtServer := e2e.StartManagementServer(t, e2e.ManagementServerOptions{SupportLoadReportingService: true}) |
| 567 | |
| 568 | // Create bootstrap configuration pointing to the above management server. |
| 569 | nodeID := uuid.New().String() |
| 570 | bc := e2e.DefaultBootstrapContents(t, nodeID, mgmtServer.Address) |
| 571 | |
| 572 | // Create an xDS resolver with the above bootstrap configuration. |
| 573 | resolverBuilder, err := internal.NewXDSResolverWithConfigForTesting.(func([]byte) (resolver.Builder, error))(bc) |
| 574 | if err != nil { |
| 575 | t.Fatalf("Failed to create xDS resolver for testing: %v", err) |
| 576 | } |
| 577 | |
| 578 | // Start a server backend exposing the test service. |
| 579 | f := &stubserver.StubServer{ |
| 580 | FullDuplexCallF: func(stream testgrpc.TestService_FullDuplexCallServer) error { |
| 581 | for { |
| 582 | if _, err := stream.Recv(); err != nil { |
| 583 | return err |
| 584 | } |
| 585 | } |
| 586 | }, |
| 587 | } |
| 588 | server := stubserver.StartTestService(t, f) |
| 589 | defer server.Stop() |
| 590 | |
| 591 | // Configure xDS resources on the management server with drops |
| 592 | // configuration that drops one RPC for every 50 RPCs made. |
| 593 | const ( |
| 594 | dropReason = "test-dropping-category" |
| 595 | dropNumerator = 1 |
| 596 | dropDenominator = 50 |
| 597 | serviceName = "my-test-xds-service" |
| 598 | errorTolerance = 0.05 |
| 599 | ) |
| 600 | wantRPCDropRate := float64(dropNumerator) / float64(dropDenominator) |
| 601 | rpcCount := computeIdealNumRpcs(wantRPCDropRate, errorTolerance) |
| 602 | t.Logf("About to send %d RPCs to test drop rate of %v", rpcCount, wantRPCDropRate) |
| 603 | |
| 604 | resources := e2e.DefaultClientResources(e2e.ResourceParams{ |
| 605 | DialTarget: serviceName, |
| 606 | NodeID: nodeID, |
| 607 | Host: "localhost", |
| 608 | Port: testutils.ParsePort(t, server.Address), |
| 609 | }) |
| 610 | resources.Clusters[0].LrsServer = &v3corepb.ConfigSource{ |
| 611 | ConfigSourceSpecifier: &v3corepb.ConfigSource_Self{ |
| 612 | Self: &v3corepb.SelfConfigSource{}, |
| 613 | }, |
| 614 | } |
| 615 | resources.Endpoints = []*v3endpointpb.ClusterLoadAssignment{ |
| 616 | e2e.EndpointResourceWithOptions(e2e.EndpointOptions{ |
| 617 | ClusterName: "endpoints-" + serviceName, |
| 618 | Host: "localhost", |
| 619 | Localities: []e2e.LocalityOptions{ |
| 620 | { |
| 621 | Backends: []e2e.BackendOptions{{Ports: []uint32{testutils.ParsePort(t, server.Address)}}}, |
nothing calls this directly
no test coverage detected