Tests basic functionality with one address. With only one address, load reporting doesn't affect routing at all.
(t *testing.T)
| 171 | // Tests basic functionality with one address. With only one address, load |
| 172 | // reporting doesn't affect routing at all. |
| 173 | func (s) TestBalancer_OneAddress(t *testing.T) { |
| 174 | testCases := []struct { |
| 175 | rt reportType |
| 176 | cfg iwrr.LBConfig |
| 177 | }{ |
| 178 | {rt: reportNone, cfg: perCallConfig}, |
| 179 | {rt: reportCall, cfg: perCallConfig}, |
| 180 | {rt: reportOOB, cfg: oobConfig}, |
| 181 | } |
| 182 | |
| 183 | for _, tc := range testCases { |
| 184 | t.Run(fmt.Sprintf("reportType:%v", tc.rt), func(t *testing.T) { |
| 185 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 186 | defer cancel() |
| 187 | |
| 188 | srv := startServer(t, tc.rt) |
| 189 | |
| 190 | sc := svcConfig(t, tc.cfg) |
| 191 | if err := srv.StartClient(grpc.WithDefaultServiceConfig(sc)); err != nil { |
| 192 | t.Fatalf("Error starting client: %v", err) |
| 193 | } |
| 194 | |
| 195 | // Perform many RPCs to ensure the LB policy works with 1 address. |
| 196 | for i := 0; i < 100; i++ { |
| 197 | srv.callMetrics.SetQPS(float64(i)) |
| 198 | srv.oobMetrics.SetQPS(float64(i)) |
| 199 | if _, err := srv.Client.EmptyCall(ctx, &testpb.Empty{}); err != nil { |
| 200 | t.Fatalf("Error from EmptyCall: %v", err) |
| 201 | } |
| 202 | time.Sleep(time.Millisecond) // Delay; test will run 100ms and should perform ~10 weight updates |
| 203 | } |
| 204 | }) |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | // TestWRRMetricsBasic tests metrics emitted from the WRR balancer. It |
| 209 | // configures a weighted round robin balancer as the top level balancer of a |
nothing calls this directly
no test coverage detected