src/tests/slave_tests.cpp
TEST_F(SlaveTest, PingTimeoutSomePings)
{
  // Start a master.
  master::Flags masterFlags = CreateMasterFlags();
  Try<Owned<cluster::Master>> master = StartMaster(masterFlags);
  ASSERT_SOME(master);

  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);

  Clock::pause();

  // Ensure a ping reaches the slave.
  Future<Message> ping = FUTURE_MESSAGE(
      Eq(PingSlaveMessage().GetTypeName()), _, _);

  Clock::advance(masterFlags.slave_ping_timeout);

  AWAIT_READY(ping);

  // Now block further pings from the master and advance
  // the clock to trigger a re-detection and re-registration on
  // the slave.
  DROP_PROTOBUFS(PingSlaveMessage(), _, _);

  Future<Nothing> detected = FUTURE_DISPATCH(_, &Slave::detected);

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

  Clock::advance(slave::DEFAULT_MASTER_PING_TIMEOUT());

  AWAIT_READY(detected);
  AWAIT_READY(slaveReregisteredMessage);
}
// This test ensures that the slave will re-register with the master
// if it stops receiving pings.
This test ensures that the slave will re-register with the master
if it stops receiving pings.
This test ensures that the slave will re - register with the master if it stops receiving pings .
TEST_F(SlaveTest, PingTimeoutSomePings)
{
  master::Flags masterFlags = CreateMasterFlags();
  Try<Owned<cluster::Master>> master = StartMaster(masterFlags);
  ASSERT_SOME(master);
  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);
  Clock::pause();
  Future<Message> ping = FUTURE_MESSAGE(
      Eq(PingSlaveMessage().GetTypeName()), _, _);
  Clock::advance(masterFlags.slave_ping_timeout);
  AWAIT_READY(ping);
  DROP_PROTOBUFS(PingSlaveMessage(), _, _);
  Future<Nothing> detected = FUTURE_DISPATCH(_, &Slave::detected);
  Future<SlaveReregisteredMessage> slaveReregisteredMessage =
    FUTURE_PROTOBUF(SlaveReregisteredMessage(), _, _);
  Clock::advance(slave::DEFAULT_MASTER_PING_TIMEOUT());
  AWAIT_READY(detected);
  AWAIT_READY(slaveReregisteredMessage);
}
TEST_F ( SlaveTest , PingTimeoutSomePings ) { master :: Flags masterFlags = CreateMasterFlags ( ) ; Try < Owned < cluster :: Master > > master = StartMaster ( masterFlags ) ; ASSERT_SOME ( master ) ; 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 ) ; Clock :: pause ( ) ; Future < Message > ping = FUTURE_MESSAGE ( Eq ( PingSlaveMessage ( ) . GetTypeName ( ) ) , _ , _ ) ; Clock :: advance ( masterFlags . slave_ping_timeout ) ; AWAIT_READY ( ping ) ; DROP_PROTOBUFS ( PingSlaveMessage ( ) , _ , _ ) ; Future < Nothing > detected = FUTURE_DISPATCH ( _ , & Slave :: detected ) ; Future < SlaveReregisteredMessage > slaveReregisteredMessage = FUTURE_PROTOBUF ( SlaveReregisteredMessage ( ) , _ , _ ) ; Clock :: advance ( slave :: DEFAULT_MASTER_PING_TIMEOUT ( ) ) ; AWAIT_READY ( detected ) ; AWAIT_READY ( slaveReregisteredMessage ) ; }
This test ensures that the slave will re-register with the master
if it stops receiving pings.
This test ensures that the slave will re - register with the master if it stops receiving pings .
// Start a master. // Start a slave. // Ensure a ping reaches the slave. // Now block further pings from the master and advance // the clock to trigger a re-detection and re-registration on // the slave.