  void runHealthCheck(std::string expected_host) {

    cluster_->info_->stats().upstream_cx_total_.inc();

    expectSessionCreate();
    expectHealthcheckStart(0);

    EXPECT_CALL(test_sessions_[0]->request_encoder_, encodeHeaders(_, false))
        .WillOnce(Invoke([&](const Http::RequestHeaderMap& headers, bool) -> Http::Status {
          EXPECT_EQ(Http::Headers::get().ContentTypeValues.Grpc, headers.getContentTypeValue());
          EXPECT_EQ(std::string("/grpc.health.v1.Health/Check"), headers.getPathValue());
          EXPECT_EQ(Http::Headers::get().SchemeValues.Http, headers.getSchemeValue());
          EXPECT_NE(nullptr, headers.Method());
          EXPECT_EQ(expected_host, headers.getHostValue());
          EXPECT_EQ(std::chrono::milliseconds(1000).count(),
                    Envoy::Grpc::Common::getGrpcTimeout(headers).value().count());
          return Http::okStatus();
        }));
    EXPECT_CALL(test_sessions_[0]->request_encoder_, encodeData(_, true))
        .WillOnce(Invoke([&](Buffer::Instance& data, bool) {
          std::vector<Grpc::Frame> decoded_frames;
          Grpc::Decoder decoder;
          ASSERT_TRUE(decoder.decode(data, decoded_frames));
          ASSERT_EQ(1U, decoded_frames.size());
          auto& frame = decoded_frames[0];
          Buffer::ZeroCopyInputStreamImpl stream(std::move(frame.data_));
          grpc::health::v1::HealthCheckRequest request;
          ASSERT_TRUE(request.ParseFromZeroCopyStream(&stream));
          EXPECT_EQ("service", request.service());
        }));
    health_checker_->start();

    EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.max_interval", _));
    EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.min_interval", _))
        .WillOnce(Return(45000));
    expectHealthcheckStop(0, 45000);

    // Host state should not be changed (remains healthy).
    EXPECT_CALL(*this, onHostStatus(cluster_->prioritySet().getMockHostSet(0)->hosts_[0],
                                    HealthTransition::Unchanged));
    respondServiceStatus(0, grpc::health::v1::HealthCheckResponse::SERVING);
    expectHostHealthy(true);
  }
  void runHealthCheck(std::string expected_host) {

    cluster_->info_->stats().upstream_cx_total_.inc();

    expectSessionCreate();
    expectHealthcheckStart(0);

    EXPECT_CALL(test_sessions_[0]->request_encoder_, encodeHeaders(_, false))
        .WillOnce(Invoke([&](const Http::RequestHeaderMap& headers, bool) -> Http::Status {
          EXPECT_EQ(Http::Headers::get().ContentTypeValues.Grpc, headers.getContentTypeValue());
          EXPECT_EQ(std::string("/grpc.health.v1.Health/Check"), headers.getPathValue());
          EXPECT_EQ(Http::Headers::get().SchemeValues.Http, headers.getSchemeValue());
          EXPECT_NE(nullptr, headers.Method());
          EXPECT_EQ(expected_host, headers.getHostValue());
          EXPECT_EQ(std::chrono::milliseconds(1000).count(),
                    Envoy::Grpc::Common::getGrpcTimeout(headers).value().count());
          return Http::okStatus();
        }));
    EXPECT_CALL(test_sessions_[0]->request_encoder_, encodeData(_, true))
        .WillOnce(Invoke([&](Buffer::Instance& data, bool) {
          std::vector<Grpc::Frame> decoded_frames;
          Grpc::Decoder decoder;
          ASSERT_TRUE(decoder.decode(data, decoded_frames));
          ASSERT_EQ(1U, decoded_frames.size());
          auto& frame = decoded_frames[0];
          Buffer::ZeroCopyInputStreamImpl stream(std::move(frame.data_));
          grpc::health::v1::HealthCheckRequest request;
          ASSERT_TRUE(request.ParseFromZeroCopyStream(&stream));
          EXPECT_EQ("service", request.service());
        }));
    health_checker_->start();

    EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.max_interval", _));
    EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.min_interval", _))
        .WillOnce(Return(45000));
    expectHealthcheckStop(0, 45000);

     
    EXPECT_CALL(*this, onHostStatus(cluster_->prioritySet().getMockHostSet(0)->hosts_[0],
                                    HealthTransition::Unchanged));
    respondServiceStatus(0, grpc::health::v1::HealthCheckResponse::SERVING);
    expectHostHealthy(true);
  }