diff --git a/health/health.go b/health/health.go index 3a836f2a..568065e3 100644 --- a/health/health.go +++ b/health/health.go @@ -24,10 +24,14 @@ func NewHealthServer() *HealthServer { } func (s *HealthServer) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) { - service := in.Service s.mu.Lock() defer s.mu.Unlock() - if status, ok := s.statusMap[service]; ok { + if in.Service == "" { + return &healthpb.HealthCheckResponse{ + Status: healthpb.HealthCheckResponse_SERVING, + }, nil + } + if status, ok := s.statusMap[in.Service]; ok { return &healthpb.HealthCheckResponse{ Status: status, }, nil diff --git a/test/end2end_test.go b/test/end2end_test.go index 1c9cc460..14748354 100644 --- a/test/end2end_test.go +++ b/test/end2end_test.go @@ -453,11 +453,18 @@ func testHealthCheckServingStatus(t *testing.T, e env) { hs := health.NewHealthServer() s, cc := setUp(hs, math.MaxUint32, "", e) defer tearDown(s, cc) + out, err := healthCheck(1*time.Second, cc, "") + if err != nil { + t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, ", err) + } + if out.Status != healthpb.HealthCheckResponse_SERVING { + t.Fatalf("Got the serving status %v, want SERVING", out.Status) + } if _, err := healthCheck(1*time.Second, cc, "grpc.health.v1alpha.HealthCheck"); err != grpc.Errorf(codes.NotFound, "unknown service") { t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, error code %d", err, codes.NotFound) } hs.SetServingStatus("grpc.health.v1alpha.HealthCheck", healthpb.HealthCheckResponse_SERVING) - out, err := healthCheck(1*time.Second, cc, "grpc.health.v1alpha.HealthCheck") + out, err = healthCheck(1*time.Second, cc, "grpc.health.v1alpha.HealthCheck") if err != nil { t.Fatalf("HealthCheck/Check(_, _) = _, %v, want _, ", err) }