Tests that ring hash policy that hashes using a random value.
(t *testing.T)
| 870 | |
| 871 | // Tests that ring hash policy that hashes using a random value. |
| 872 | func (s) TestRingHash_NoHashPolicy(t *testing.T) { |
| 873 | backends := backendAddrs(startTestServiceBackends(t, 2)) |
| 874 | numRPCs := computeIdealNumberOfRPCs(t, .5, errorTolerance) |
| 875 | |
| 876 | const clusterName = "cluster" |
| 877 | endpoints := endpointResource(t, clusterName, backends) |
| 878 | cluster := e2e.ClusterResourceWithOptions(e2e.ClusterOptions{ |
| 879 | ClusterName: clusterName, |
| 880 | ServiceName: clusterName, |
| 881 | }) |
| 882 | setRingHashLBPolicyWithHighMinRingSize(t, cluster) |
| 883 | route := e2e.DefaultRouteConfig("new_route", virtualHostName, clusterName) |
| 884 | listener := e2e.DefaultClientListener(virtualHostName, route.Name) |
| 885 | |
| 886 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 887 | defer cancel() |
| 888 | |
| 889 | xdsServer, nodeID, xdsResolver := setupManagementServerAndResolver(t) |
| 890 | if err := xdsServer.Update(ctx, xdsUpdateOpts(nodeID, endpoints, cluster, route, listener)); err != nil { |
| 891 | t.Fatalf("Failed to update xDS resources: %v", err) |
| 892 | } |
| 893 | |
| 894 | conn, err := grpc.NewClient("xds:///test.server", grpc.WithResolvers(xdsResolver), grpc.WithTransportCredentials(insecure.NewCredentials())) |
| 895 | if err != nil { |
| 896 | t.Fatalf("Failed to create client: %s", err) |
| 897 | } |
| 898 | defer conn.Close() |
| 899 | client := testgrpc.NewTestServiceClient(conn) |
| 900 | |
| 901 | // Send a large number of RPCs and check that they are distributed randomly. |
| 902 | gotPerBackend := checkRPCSendOK(ctx, t, client, numRPCs) |
| 903 | for _, backend := range backends { |
| 904 | got := float64(gotPerBackend[backend]) / float64(numRPCs) |
| 905 | want := .5 |
| 906 | if !cmp.Equal(got, want, cmpopts.EquateApprox(0, errorTolerance)) { |
| 907 | t.Errorf("Fraction of RPCs to backend %s: got %v, want %v (margin: +-%v)", backend, got, want, errorTolerance) |
| 908 | } |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | // Tests that we observe endpoint weights. |
| 913 | func (s) TestRingHash_EndpointWeights(t *testing.T) { |
nothing calls this directly
no test coverage detected