TEST_F(HttpHealthCheckerImplTest, TimeoutAfterDisconnect) {
  setupNoServiceValidationHC();
  cluster_->prioritySet().getMockHostSet(0)->hosts_ = {
      makeTestHost(cluster_->info_, "tcp://127.0.0.1:80", simTime())};
  expectSessionCreate();
  expectStreamCreate(0);
  EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true));
  EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _)).Times(2);
  health_checker_->start();

  EXPECT_CALL(*this, onHostStatus(_, HealthTransition::ChangePending));
  EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(_, _)).Times(2);
  EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer());
  for (auto& session : test_sessions_) {
    session->client_connection_->close(Network::ConnectionCloseType::NoFlush);
  }

  EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed));
  EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _));
  EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer());

  test_sessions_[0]->timeout_timer_->enableTimer(std::chrono::seconds(10), nullptr);
  test_sessions_[0]->timeout_timer_->invokeCallback();
  EXPECT_EQ(Host::Health::Unhealthy,
            cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->health());
}
TEST_F(HttpHealthCheckerImplTest, TimeoutAfterDisconnect) {
  setupNoServiceValidationHC();
  cluster_->prioritySet().getMockHostSet(0)->hosts_ = {
      makeTestHost(cluster_->info_, "tcp://127.0.0.1:80", simTime())};
  expectSessionCreate();
  expectStreamCreate(0);
  EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true));
  EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _)).Times(2);
  health_checker_->start();

  EXPECT_CALL(*this, onHostStatus(_, HealthTransition::ChangePending));
  EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(_, _)).Times(2);
  EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer());
  for (auto& session : test_sessions_) {
    session->client_connection_->close(Network::ConnectionCloseType::NoFlush);
  }

  EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed));
  EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _));
  EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer());

  test_sessions_[0]->timeout_timer_->enableTimer(std::chrono::seconds(10), nullptr);
  test_sessions_[0]->timeout_timer_->invokeCallback();
  EXPECT_EQ(Host::Health::Unhealthy,
            cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->health());
}