Tests the behavior of the weighted_target LB policy when there are no targets configured. It verifies that the LB policy sets the overall channel state to TRANSIENT_FAILURE and fails RPCs with an expected status code and message.
(t *testing.T)
| 175 | // configured. It verifies that the LB policy sets the overall channel state to |
| 176 | // TRANSIENT_FAILURE and fails RPCs with an expected status code and message. |
| 177 | func (s) TestWeightedTarget_NoTargets(t *testing.T) { |
| 178 | dopts := []grpc.DialOption{ |
| 179 | grpc.WithTransportCredentials(insecure.NewCredentials()), |
| 180 | grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"weighted_target_experimental":{}}]}`), |
| 181 | } |
| 182 | cc, err := grpc.NewClient("passthrough:///test.server", dopts...) |
| 183 | if err != nil { |
| 184 | t.Fatalf("grpc.NewClient() failed: %v", err) |
| 185 | } |
| 186 | defer cc.Close() |
| 187 | cc.Connect() |
| 188 | |
| 189 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 190 | defer cancel() |
| 191 | client := testgrpc.NewTestServiceClient(cc) |
| 192 | _, err = client.EmptyCall(ctx, &testpb.Empty{}) |
| 193 | if err == nil { |
| 194 | t.Error("EmptyCall() succeeded, want failure") |
| 195 | } |
| 196 | if gotCode, wantCode := status.Code(err), codes.Unavailable; gotCode != wantCode { |
| 197 | t.Errorf("EmptyCall() failed with code = %v, want %s", gotCode, wantCode) |
| 198 | } |
| 199 | if gotMsg, wantMsg := err.Error(), "no targets to pick from"; !strings.Contains(gotMsg, wantMsg) { |
| 200 | t.Errorf("EmptyCall() failed with message = %q, want to contain %q", gotMsg, wantMsg) |
| 201 | } |
| 202 | if gotState, wantState := cc.GetState(), connectivity.TransientFailure; gotState != wantState { |
| 203 | t.Errorf("cc.GetState() = %v, want %v", gotState, wantState) |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | // TestWeightedTarget covers the cases that a sub-balancer is added and a |
| 208 | // sub-balancer is removed. It verifies that the addresses and balancer configs |
nothing calls this directly
no test coverage detected