(t *testing.T)
| 192 | } |
| 193 | |
| 194 | func (s) TestHealthCheckWatchStateChange(t *testing.T) { |
| 195 | _, lis, ts := setupServer(t, nil) |
| 196 | |
| 197 | // The table below shows the expected series of addrConn connectivity transitions when server |
| 198 | // updates its health status. As there's only one addrConn corresponds with the ClientConn in this |
| 199 | // test, we use ClientConn's connectivity state as the addrConn connectivity state. |
| 200 | //+------------------------------+-------------------------------------------+ |
| 201 | //| Health Check Returned Status | Expected addrConn Connectivity Transition | |
| 202 | //+------------------------------+-------------------------------------------+ |
| 203 | //| NOT_SERVING | ->TRANSIENT FAILURE | |
| 204 | //| SERVING | ->READY | |
| 205 | //| SERVICE_UNKNOWN | ->TRANSIENT FAILURE | |
| 206 | //| SERVING | ->READY | |
| 207 | //| UNKNOWN | ->TRANSIENT FAILURE | |
| 208 | //+------------------------------+-------------------------------------------+ |
| 209 | ts.SetServingStatus("foo", healthpb.HealthCheckResponse_NOT_SERVING) |
| 210 | |
| 211 | cc, r := setupClient(t, nil) |
| 212 | r.UpdateState(resolver.State{ |
| 213 | Addresses: []resolver.Address{{Addr: lis.Addr().String()}}, |
| 214 | ServiceConfig: parseServiceConfig(t, r, `{ |
| 215 | "healthCheckConfig": { |
| 216 | "serviceName": "foo" |
| 217 | }, |
| 218 | "loadBalancingConfig": [{"round_robin":{}}] |
| 219 | }`)}) |
| 220 | |
| 221 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 222 | defer cancel() |
| 223 | testutils.AwaitNotState(ctx, t, cc, connectivity.Idle) |
| 224 | testutils.AwaitNotState(ctx, t, cc, connectivity.Connecting) |
| 225 | testutils.AwaitState(ctx, t, cc, connectivity.TransientFailure) |
| 226 | if s := cc.GetState(); s != connectivity.TransientFailure { |
| 227 | t.Fatalf("ClientConn is in %v state, want TRANSIENT FAILURE", s) |
| 228 | } |
| 229 | |
| 230 | ts.SetServingStatus("foo", healthpb.HealthCheckResponse_SERVING) |
| 231 | testutils.AwaitNotState(ctx, t, cc, connectivity.TransientFailure) |
| 232 | if s := cc.GetState(); s != connectivity.Ready { |
| 233 | t.Fatalf("ClientConn is in %v state, want READY", s) |
| 234 | } |
| 235 | |
| 236 | ts.SetServingStatus("foo", healthpb.HealthCheckResponse_SERVICE_UNKNOWN) |
| 237 | testutils.AwaitNotState(ctx, t, cc, connectivity.Ready) |
| 238 | if s := cc.GetState(); s != connectivity.TransientFailure { |
| 239 | t.Fatalf("ClientConn is in %v state, want TRANSIENT FAILURE", s) |
| 240 | } |
| 241 | |
| 242 | ts.SetServingStatus("foo", healthpb.HealthCheckResponse_SERVING) |
| 243 | testutils.AwaitNotState(ctx, t, cc, connectivity.TransientFailure) |
| 244 | if s := cc.GetState(); s != connectivity.Ready { |
| 245 | t.Fatalf("ClientConn is in %v state, want READY", s) |
| 246 | } |
| 247 | |
| 248 | ts.SetServingStatus("foo", healthpb.HealthCheckResponse_UNKNOWN) |
| 249 | testutils.AwaitNotState(ctx, t, cc, connectivity.Ready) |
| 250 | if s := cc.GetState(); s != connectivity.TransientFailure { |
| 251 | t.Fatalf("ClientConn is in %v state, want TRANSIENT FAILURE", s) |
nothing calls this directly
no test coverage detected