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

Method TestHealthCheckWithClientConnClose

test/healthcheck_test.go:495–542  ·  view source on GitHub ↗

ClientConn close will lead to its addrConns being torn down.

(t *testing.T)

Source from the content-addressed store, hash-verified

493
494// ClientConn close will lead to its addrConns being torn down.
495func (s) TestHealthCheckWithClientConnClose(t *testing.T) {
496 _, lis, ts := setupServer(t, nil)
497 ts.SetServingStatus("foo", healthpb.HealthCheckResponse_SERVING)
498
499 hcEnterChan, hcExitChan := setupHealthCheckWrapper(t)
500 cc, r := setupClient(t, &clientConfig{})
501 tc := testgrpc.NewTestServiceClient(cc)
502 r.UpdateState(resolver.State{
503 Addresses: []resolver.Address{{Addr: lis.Addr().String()}},
504 ServiceConfig: parseServiceConfig(t, r, (fmt.Sprintf(`{
505 "healthCheckConfig": {
506 "serviceName": "foo"
507 },
508 "loadBalancingConfig": [{"%s":{}}]
509 }`, roundrobin.Name)))})
510
511 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
512 defer cancel()
513 // make some rpcs to make sure connection is working.
514 if err := verifyResultWithDelay(func() (bool, error) {
515 if _, err := tc.EmptyCall(ctx, &testpb.Empty{}); err != nil {
516 return false, fmt.Errorf("TestService/EmptyCall(_, _) = _, %v, want _, <nil>", err)
517 }
518 return true, nil
519 }); err != nil {
520 t.Fatal(err)
521 }
522
523 select {
524 case <-hcExitChan:
525 t.Fatal("Health check function has exited, which is not expected.")
526 default:
527 }
528
529 // trigger addrConn teardown
530 cc.Close()
531
532 select {
533 case <-hcExitChan:
534 case <-time.After(5 * time.Second):
535 select {
536 case <-hcEnterChan:
537 default:
538 t.Fatal("Health check function has not entered after 5s.")
539 }
540 t.Fatal("Health check function has not exited after 5s.")
541 }
542}
543
544// This test is to test the logic in the createTransport after the health check function returns which
545// closes the skipReset channel(since it has not been closed inside health check func) to unblock

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
CloseMethod · 0.65
SetServingStatusMethod · 0.45

Tested by

no test coverage detected