TEST_F(GrpcHealthCheckerImplTest, GoAwayProbeInProgressBadResponse) {
  setupHCWithUnhealthyThreshold(/*threshold=*/1);
  cluster_->prioritySet().getMockHostSet(0)->hosts_ = {
      makeTestHost(cluster_->info_, "tcp://127.0.0.1:80", simTime())};

  expectSessionCreate();
  expectHealthcheckStart(0);
  EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true));
  health_checker_->start();

  expectHealthcheckStop(0);
  // Unhealthy threshold is 1 so first bad response causes unhealthy
  EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed));
  EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _));

  // GOAWAY during check should be handled gracefully.
  test_sessions_[0]->codec_client_->raiseGoAway(Http::GoAwayErrorCode::NoError);
  expectHostHealthy(true);

  respondResponseSpec(0, ResponseSpec{{{":status", "200"}, {"content-type", "application/grpc"}},
                                      {ResponseSpec::invalidChunk()},
                                      {}});
  expectHostHealthy(false);

  // GOAWAY should cause a new connection to be created.
  expectClientCreate(0);
  expectHealthcheckStart(0);
  test_sessions_[0]->interval_timer_->invokeCallback();

  expectHealthcheckStop(0);
  // Healthy threshold is 2, so the we'ere pending a state change.
  EXPECT_CALL(*this, onHostStatus(_, HealthTransition::ChangePending));
  respondServiceStatus(0, grpc::health::v1::HealthCheckResponse::SERVING);
  expectHostHealthy(false);
}
TEST_F(GrpcHealthCheckerImplTest, GoAwayProbeInProgressBadResponse) {
  setupHCWithUnhealthyThreshold( 1);
  cluster_->prioritySet().getMockHostSet(0)->hosts_ = {
      makeTestHost(cluster_->info_, "tcp://127.0.0.1:80", simTime())};

  expectSessionCreate();
  expectHealthcheckStart(0);
  EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true));
  health_checker_->start();

  expectHealthcheckStop(0);
   
  EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed));
  EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _));

   
  test_sessions_[0]->codec_client_->raiseGoAway(Http::GoAwayErrorCode::NoError);
  expectHostHealthy(true);

  respondResponseSpec(0, ResponseSpec{{{":status", "200"}, {"content-type", "application/grpc"}},
                                      {ResponseSpec::invalidChunk()},
                                      {}});
  expectHostHealthy(false);

   
  expectClientCreate(0);
  expectHealthcheckStart(0);
  test_sessions_[0]->interval_timer_->invokeCallback();

  expectHealthcheckStop(0);
   
  EXPECT_CALL(*this, onHostStatus(_, HealthTransition::ChangePending));
  respondServiceStatus(0, grpc::health::v1::HealthCheckResponse::SERVING);
  expectHostHealthy(false);
}