diff --git a/integration/v3_health_check_test.go b/integration/v3_health_check_test.go new file mode 100644 index 000000000000..0c74f99f087f --- /dev/null +++ b/integration/v3_health_check_test.go @@ -0,0 +1,48 @@ +// Copyright 2017 The etcd Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package integration + +import ( + "context" + "testing" + + "github.com/coreos/etcd/pkg/testutil" + + "google.golang.org/grpc" + healthpb "google.golang.org/grpc/health/grpc_health_v1" +) + +func TestHealthCheck(t *testing.T) { + defer testutil.AfterTest(t) + + clus := NewClusterV3(t, &ClusterConfig{Size: 1}) + defer clus.Terminate(t) + + cli := healthpb.NewHealthClient(clus.RandClient().ActiveConnection()) + resp, err := cli.Check(context.TODO(), &healthpb.HealthCheckRequest{}) + if err != nil { + t.Fatal(err) + } + if resp.Status != healthpb.HealthCheckResponse_SERVING { + t.Fatalf("status expected %s, got %s", healthpb.HealthCheckResponse_SERVING, resp.Status) + } + + clus.Members[0].grpcServer.GracefulStop() + + _, err = cli.Check(context.TODO(), &healthpb.HealthCheckRequest{}) + if grpc.ErrorDesc(err) != "there is no address available" { + t.Fatalf("error expected 'there is no address available', got %v", err) + } +}