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

Method TestWrrLocality

test/xds/xds_client_custom_lb_test.go:95–269  ·  view source on GitHub ↗

TestWRRLocality tests RPC distribution across a scenario with 5 backends, with 2 backends in a locality with weight 1, and 3 backends in a second locality with weight 2. Through xDS, the test configures a wrr_locality_balancer with either a round robin or custom (specifying pick first) child load ba

(t *testing.T)

Source from the content-addressed store, hash-verified

93// first) child load balancing policy, and asserts the correct distribution
94// based on the locality weights and the endpoint picking policy specified.
95func (s) TestWrrLocality(t *testing.T) {
96 backend1 := stubserver.StartTestService(t, nil)
97 port1 := testutils.ParsePort(t, backend1.Address)
98 defer backend1.Stop()
99 backend2 := stubserver.StartTestService(t, nil)
100 port2 := testutils.ParsePort(t, backend2.Address)
101 defer backend2.Stop()
102 backend3 := stubserver.StartTestService(t, nil)
103 port3 := testutils.ParsePort(t, backend3.Address)
104 defer backend3.Stop()
105 backend4 := stubserver.StartTestService(t, nil)
106 port4 := testutils.ParsePort(t, backend4.Address)
107 defer backend4.Stop()
108 backend5 := stubserver.StartTestService(t, nil)
109 port5 := testutils.ParsePort(t, backend5.Address)
110 defer backend5.Stop()
111 const serviceName = "my-service-client-side-xds"
112
113 tests := []struct {
114 name string
115 // Configuration will be specified through load_balancing_policy field.
116 wrrLocalityConfiguration *v3wrrlocalitypb.WrrLocality
117 addressDistributionWant []struct {
118 addr string
119 count int
120 }
121 }{
122 {
123 name: "rr_child",
124 wrrLocalityConfiguration: wrrLocality(t, &v3roundrobinpb.RoundRobin{}),
125 // Each addresses expected probability is locality weight of
126 // locality / total locality weights multiplied by 1 / number of
127 // endpoints in each locality (due to round robin across endpoints
128 // in a locality). Thus, address 1 and address 2 have 1/3 * 1/2
129 // probability, and addresses 3 4 5 have 2/3 * 1/3 probability of
130 // being routed to.
131 addressDistributionWant: []struct {
132 addr string
133 count int
134 }{
135 {addr: backend1.Address, count: 6},
136 {addr: backend2.Address, count: 6},
137 {addr: backend3.Address, count: 8},
138 {addr: backend4.Address, count: 8},
139 {addr: backend5.Address, count: 8},
140 },
141 },
142 // This configures custom lb as the child of wrr_locality, which points
143 // to our pick_first implementation. Thus, the expected distribution of
144 // addresses is locality weight of locality / total locality weights as
145 // the probability of picking the first backend within the locality
146 // (e.g. Address 1 for locality 1, and Address 3 for locality 2).
147 {
148 name: "custom_lb_child_pick_first",
149 wrrLocalityConfiguration: wrrLocality(t, &v3xdsxdstypepb.TypedStruct{
150 TypeUrl: "type.googleapis.com/pick_first",
151 Value: &structpb.Struct{},
152 }),

Callers

nothing calls this directly

Calls 15

StartTestServiceFunction · 0.92
ParsePortFunction · 0.92
DefaultClientListenerFunction · 0.92
DefaultRouteConfigFunction · 0.92
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithResolversFunction · 0.92
wrrLocalityFunction · 0.70

Tested by

no test coverage detected