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

Method TestHealthCheckWithConnClose

test/healthcheck_test.go:365–411  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

363}
364
365func (s) TestHealthCheckWithConnClose(t *testing.T) {
366 s, lis, ts := setupServer(t, nil)
367 ts.SetServingStatus("foo", healthpb.HealthCheckResponse_SERVING)
368
369 hcEnterChan, hcExitChan := setupHealthCheckWrapper(t)
370 cc, r := setupClient(t, &clientConfig{})
371 tc := testgrpc.NewTestServiceClient(cc)
372 r.UpdateState(resolver.State{
373 Addresses: []resolver.Address{{Addr: lis.Addr().String()}},
374 ServiceConfig: parseServiceConfig(t, r, fmt.Sprintf(`{
375 "healthCheckConfig": {
376 "serviceName": "foo"
377 },
378 "loadBalancingConfig": [{"%s":{}}]
379 }`, roundrobin.Name))})
380
381 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
382 defer cancel()
383 // make some rpcs to make sure connection is working.
384 if err := verifyResultWithDelay(func() (bool, error) {
385 if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); err != nil {
386 return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, <nil>", err)
387 }
388 return true, nil
389 }); err != nil {
390 t.Fatal(err)
391 }
392
393 select {
394 case <-hcExitChan:
395 t.Fatal("Health check function has exited, which is not expected.")
396 default:
397 }
398 // server closes the connection
399 s.Stop()
400
401 select {
402 case <-hcExitChan:
403 case <-time.After(5 * time.Second):
404 select {
405 case <-hcEnterChan:
406 default:
407 t.Fatal("Health check function has not entered after 5s.")
408 }
409 t.Fatal("Health check function has not exited after 5s.")
410 }
411}
412
413// addrConn drain happens when addrConn gets torn down due to its address being no longer in the
414// address list returned by the resolver.

Callers

nothing calls this directly

Calls 13

EmptyCallMethod · 0.95
setupServerFunction · 0.85
setupHealthCheckWrapperFunction · 0.85
setupClientFunction · 0.85
parseServiceConfigFunction · 0.70
verifyResultWithDelayFunction · 0.70
UpdateStateMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.65
FatalMethod · 0.65
StopMethod · 0.65
SetServingStatusMethod · 0.45

Tested by

no test coverage detected