src/tests/slave_tests.cpp
TEST_F(SlaveTest, PingTimeoutNoPings)
{
  // Set shorter ping timeout values.
  master::Flags masterFlags = CreateMasterFlags();
  masterFlags.slave_ping_timeout = Seconds(5);
  masterFlags.max_slave_ping_timeouts = 2u;
  Duration totalTimeout =
    masterFlags.slave_ping_timeout * masterFlags.max_slave_ping_timeouts;

  // Start a master.
  Try<Owned<cluster::Master>> master = StartMaster(masterFlags);
  ASSERT_SOME(master);

  // Block all pings to the slave.
  DROP_PROTOBUFS(PingSlaveMessage(), _, _);

  Future<SlaveRegisteredMessage> slaveRegisteredMessage =
    FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);

  Owned<MasterDetector> detector = master.get()->createDetector();

  // Start a slave.
  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get());
  ASSERT_SOME(slave);

  AWAIT_READY(slaveRegisteredMessage);
  ASSERT_TRUE(slaveRegisteredMessage.get().has_connection());
  MasterSlaveConnection connection = slaveRegisteredMessage.get().connection();
  EXPECT_EQ(totalTimeout, Seconds(connection.total_ping_timeout_seconds()));

  // Ensure the slave processes the registration message and schedules
  // the ping timeout, before we advance the clock.
  Clock::pause();
  Clock::settle();

  // Advance to the ping timeout to trigger a re-detection and
  // re-registration.
  Future<Nothing> detected = FUTURE_DISPATCH(_, &Slave::detected);

  Future<SlaveReregisteredMessage> slaveReregisteredMessage =
    FUTURE_PROTOBUF(SlaveReregisteredMessage(), _, _);

  Clock::advance(totalTimeout);

  AWAIT_READY(detected);
  AWAIT_READY(slaveReregisteredMessage);
}
// This test ensures that the slave will re-register with the master
// if it does not receive any pings after registering.
This test ensures that the slave will re-register with the master
if it does not receive any pings after registering.
This test ensures that the slave will re - register with the master if it does not receive any pings after registering .
TEST_F(SlaveTest, PingTimeoutNoPings)
{
  master::Flags masterFlags = CreateMasterFlags();
  masterFlags.slave_ping_timeout = Seconds(5);
  masterFlags.max_slave_ping_timeouts = 2u;
  Duration totalTimeout =
    masterFlags.slave_ping_timeout * masterFlags.max_slave_ping_timeouts;
  Try<Owned<cluster::Master>> master = StartMaster(masterFlags);
  ASSERT_SOME(master);
  DROP_PROTOBUFS(PingSlaveMessage(), _, _);
  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);
  ASSERT_TRUE(slaveRegisteredMessage.get().has_connection());
  MasterSlaveConnection connection = slaveRegisteredMessage.get().connection();
  EXPECT_EQ(totalTimeout, Seconds(connection.total_ping_timeout_seconds()));
  Clock::pause();
  Clock::settle();
  Future<Nothing> detected = FUTURE_DISPATCH(_, &Slave::detected);
  Future<SlaveReregisteredMessage> slaveReregisteredMessage =
    FUTURE_PROTOBUF(SlaveReregisteredMessage(), _, _);
  Clock::advance(totalTimeout);
  AWAIT_READY(detected);
  AWAIT_READY(slaveReregisteredMessage);
}
TEST_F ( SlaveTest , PingTimeoutNoPings ) { master :: Flags masterFlags = CreateMasterFlags ( ) ; masterFlags . slave_ping_timeout = Seconds ( 5 ) ; masterFlags . max_slave_ping_timeouts = 2u ; Duration totalTimeout = masterFlags . slave_ping_timeout * masterFlags . max_slave_ping_timeouts ; Try < Owned < cluster :: Master > > master = StartMaster ( masterFlags ) ; ASSERT_SOME ( master ) ; DROP_PROTOBUFS ( PingSlaveMessage ( ) , _ , _ ) ; 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 ) ; ASSERT_TRUE ( slaveRegisteredMessage . get ( ) . has_connection ( ) ) ; MasterSlaveConnection connection = slaveRegisteredMessage . get ( ) . connection ( ) ; EXPECT_EQ ( totalTimeout , Seconds ( connection . total_ping_timeout_seconds ( ) ) ) ; Clock :: pause ( ) ; Clock :: settle ( ) ; Future < Nothing > detected = FUTURE_DISPATCH ( _ , & Slave :: detected ) ; Future < SlaveReregisteredMessage > slaveReregisteredMessage = FUTURE_PROTOBUF ( SlaveReregisteredMessage ( ) , _ , _ ) ; Clock :: advance ( totalTimeout ) ; AWAIT_READY ( detected ) ; AWAIT_READY ( slaveReregisteredMessage ) ; }
This test ensures that the slave will re-register with the master
if it does not receive any pings after registering.
This test ensures that the slave will re - register with the master if it does not receive any pings after registering .
// Set shorter ping timeout values. // Start a master. // Block all pings to the slave. // Start a slave. // Ensure the slave processes the registration message and schedules // the ping timeout, before we advance the clock. // Advance to the ping timeout to trigger a re-detection and // re-registration.