src/tests/slave_tests.cpp
// This test verifies that when a slave responds to pings after the
// slave observer has scheduled it for shutdown (due to health check
// failure), the shutdown is cancelled.
This test verifies that when a slave responds to pings after the
slave observer has scheduled it for shutdown (due to health check
failure), the shutdown is cancelled.
This test verifies that when a slave responds to pings after the slave observer has scheduled it for shutdown ( due to health check failure ) the shutdown is cancelled .
TEST_F(SlaveTest, CancelSlaveShutdown)
{
  auto slaveRemovalLimiter = std::make_shared<MockRateLimiter>();
  master::Flags masterFlags = CreateMasterFlags();
  Try<Owned<cluster::Master>> master =
    StartMaster(slaveRemovalLimiter, masterFlags);
  ASSERT_SOME(master);
  Future<Message> ping = FUTURE_MESSAGE(
      Eq(PingSlaveMessage().GetTypeName()), _, _);
  DROP_PROTOBUFS(PongSlaveMessage(), _, _);
  EXPECT_NO_FUTURE_PROTOBUFS(ShutdownMessage(), _, _);
  Future<SlaveRegisteredMessage> slaveRegisteredMessage =
    FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);
  Owned<MasterDetector> detector = master.get()->createDetector();
  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get());
  ASSERT_SOME(slave);
  AWAIT_READY(slaveRegisteredMessage);
  Future<Nothing> acquire;
  Promise<Nothing> promise;
  EXPECT_CALL(*slaveRemovalLimiter, acquire())
    .WillOnce(DoAll(FutureSatisfy(&acquire),
                    Return(promise.future())));
  Clock::pause();
  size_t pings = 0;
  while (true) {
    AWAIT_READY(ping);
    pings++;
    if (pings == masterFlags.max_slave_ping_timeouts) {
      Clock::advance(masterFlags.slave_ping_timeout);
      break;
    }
    ping = FUTURE_MESSAGE(Eq(PingSlaveMessage().GetTypeName()), _, _);
    Clock::advance(masterFlags.slave_ping_timeout);
  }
  AWAIT_READY(acquire);
  Clock::settle();
  filter(NULL);
  Clock::advance(masterFlags.slave_ping_timeout);
  Clock::settle();
  ASSERT_TRUE(promise.future().hasDiscard());
  promise.discard();
  Clock::settle();
}
TEST_F ( SlaveTest , CancelSlaveShutdown ) { auto slaveRemovalLimiter = std :: make_shared < MockRateLimiter > ( ) ; master :: Flags masterFlags = CreateMasterFlags ( ) ; Try < Owned < cluster :: Master > > master = StartMaster ( slaveRemovalLimiter , masterFlags ) ; ASSERT_SOME ( master ) ; Future < Message > ping = FUTURE_MESSAGE ( Eq ( PingSlaveMessage ( ) . GetTypeName ( ) ) , _ , _ ) ; DROP_PROTOBUFS ( PongSlaveMessage ( ) , _ , _ ) ; EXPECT_NO_FUTURE_PROTOBUFS ( ShutdownMessage ( ) , _ , _ ) ; Future < SlaveRegisteredMessage > slaveRegisteredMessage = FUTURE_PROTOBUF ( SlaveRegisteredMessage ( ) , _ , _ ) ; Owned < MasterDetector > detector = master . get ( ) -> createDetector ( ) ; Try < Owned < cluster :: Slave > > slave = StartSlave ( detector . get ( ) ) ; ASSERT_SOME ( slave ) ; AWAIT_READY ( slaveRegisteredMessage ) ; Future < Nothing > acquire ; Promise < Nothing > promise ; EXPECT_CALL ( * slaveRemovalLimiter , acquire ( ) ) . WillOnce ( DoAll ( FutureSatisfy ( & acquire ) , Return ( promise . future ( ) ) ) ) ; Clock :: pause ( ) ; size_t pings = 0 ; while ( true ) { AWAIT_READY ( ping ) ; pings ++ ; if ( pings == masterFlags . max_slave_ping_timeouts ) { Clock :: advance ( masterFlags . slave_ping_timeout ) ; break ; } ping = FUTURE_MESSAGE ( Eq ( PingSlaveMessage ( ) . GetTypeName ( ) ) , _ , _ ) ; Clock :: advance ( masterFlags . slave_ping_timeout ) ; } AWAIT_READY ( acquire ) ; Clock :: settle ( ) ; filter ( NULL ) ; Clock :: advance ( masterFlags . slave_ping_timeout ) ; Clock :: settle ( ) ; ASSERT_TRUE ( promise . future ( ) . hasDiscard ( ) ) ; promise . discard ( ) ; Clock :: settle ( ) ; }
This test verifies that when a slave responds to pings after the
slave observer has scheduled it for shutdown (due to health check
failure), the shutdown is cancelled.
This test verifies that when a slave responds to pings after the slave observer has scheduled it for shutdown ( due to health check failure ) the shutdown is cancelled .
// Start a master. // Set these expectations up before we spawn the slave so that we // don't miss the first PING. // Drop all the PONGs to simulate health check timeout. // No shutdown should occur during the test! // Start a slave. // Return a pending future from the rate limiter. // Induce a health check failure of the slave. // The master should attempt to acquire a permit. // Settle to make sure the shutdown does not occur. // Reset the filters to allow pongs from the slave. // Advance clock enough to do a ping pong. // The master should have tried to cancel the removal. // Allow the cancelation and settle the clock to ensure a shutdown // does not occur.