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

  TestContainerizer containerizer;

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

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

  MockScheduler sched;
  MesosSchedulerDriver driver(
      &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);

  EXPECT_CALL(sched, registered(_, _, _));

  Future<vector<Offer>> offers;
  EXPECT_CALL(sched, resourceOffers(&driver, _))
    .WillOnce(FutureArg<1>(&offers))
    .WillRepeatedly(Return()); // Ignore subsequent offers.

  driver.start();

  AWAIT_READY(offers);
  EXPECT_NE(0u, offers.get().size());
  const Offer offer = offers.get()[0];

  // Verify that we start with no launch failures.
  JSON::Object snapshot = Metrics();
  EXPECT_EQ(0, snapshot.values["slave/container_launch_errors"]);

  EXPECT_CALL(containerizer, launch(_, _, _, _, _, _, _))
    .WillOnce(Return(Failure("Injected failure")));

  Future<TaskStatus> failureUpdate;
  EXPECT_CALL(sched, statusUpdate(&driver, _))
    .WillOnce(FutureArg<1>(&failureUpdate));

  // The above injected containerizer failure also triggers executorLost.
  EXPECT_CALL(sched, executorLost(&driver, DEFAULT_EXECUTOR_ID, _, _));

  // Try to start a task
  TaskInfo task = createTask(
      offer.slave_id(),
      Resources::parse("cpus:1;mem:32").get(),
      "sleep 1000",
      DEFAULT_EXECUTOR_ID);

  driver.launchTasks(offer.id(), {task});

  AWAIT_READY(failureUpdate);
  ASSERT_EQ(TASK_FAILED, failureUpdate.get().state());

  // After failure injection, metrics should report a single failure.
  snapshot = Metrics();
  EXPECT_EQ(1, snapshot.values["slave/container_launch_errors"]);

  driver.stop();
  driver.join();
}
// Test to verify that we increment the container launch errors metric
// when we fail to launch a container.
Test to verify that we increment the container launch errors metric
when we fail to launch a container.
Test to verify that we increment the container launch errors metric when we fail to launch a container .
TEST_F(SlaveTest, MetricsSlaveLaunchErrors)
{
  Try<Owned<cluster::Master>> master = StartMaster();
  ASSERT_SOME(master);
  TestContainerizer containerizer;
  Owned<MasterDetector> detector = master.get()->createDetector();
  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), &containerizer);
  ASSERT_SOME(slave);
  MockScheduler sched;
  MesosSchedulerDriver driver(
      &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
  EXPECT_CALL(sched, registered(_, _, _));
  Future<vector<Offer>> offers;
  EXPECT_CALL(sched, resourceOffers(&driver, _))
    .WillOnce(FutureArg<1>(&offers))
    .WillRepeatedly(Return()); 
  driver.start();
  AWAIT_READY(offers);
  EXPECT_NE(0u, offers.get().size());
  const Offer offer = offers.get()[0];
  JSON::Object snapshot = Metrics();
  EXPECT_EQ(0, snapshot.values["slave/container_launch_errors"]);
  EXPECT_CALL(containerizer, launch(_, _, _, _, _, _, _))
    .WillOnce(Return(Failure("Injected failure")));
  Future<TaskStatus> failureUpdate;
  EXPECT_CALL(sched, statusUpdate(&driver, _))
    .WillOnce(FutureArg<1>(&failureUpdate));
  EXPECT_CALL(sched, executorLost(&driver, DEFAULT_EXECUTOR_ID, _, _));
  TaskInfo task = createTask(
      offer.slave_id(),
      Resources::parse("cpus:1;mem:32").get(),
      "sleep 1000",
      DEFAULT_EXECUTOR_ID);
  driver.launchTasks(offer.id(), {task});
  AWAIT_READY(failureUpdate);
  ASSERT_EQ(TASK_FAILED, failureUpdate.get().state());
  snapshot = Metrics();
  EXPECT_EQ(1, snapshot.values["slave/container_launch_errors"]);
  driver.stop();
  driver.join();
}
TEST_F ( SlaveTest , MetricsSlaveLaunchErrors ) { Try < Owned < cluster :: Master > > master = StartMaster ( ) ; ASSERT_SOME ( master ) ; TestContainerizer containerizer ; Owned < MasterDetector > detector = master . get ( ) -> createDetector ( ) ; Try < Owned < cluster :: Slave > > slave = StartSlave ( detector . get ( ) , & containerizer ) ; ASSERT_SOME ( slave ) ; MockScheduler sched ; MesosSchedulerDriver driver ( & sched , DEFAULT_FRAMEWORK_INFO , master . get ( ) -> pid , DEFAULT_CREDENTIAL ) ; EXPECT_CALL ( sched , registered ( _ , _ , _ ) ) ; Future < vector < Offer > > offers ; EXPECT_CALL ( sched , resourceOffers ( & driver , _ ) ) . WillOnce ( FutureArg < 1 > ( & offers ) ) . WillRepeatedly ( Return ( ) ) ; driver . start ( ) ; AWAIT_READY ( offers ) ; EXPECT_NE ( 0u , offers . get ( ) . size ( ) ) ; const Offer offer = offers . get ( ) [ 0 ] ; JSON :: Object snapshot = Metrics ( ) ; EXPECT_EQ ( 0 , snapshot . values [ " " ] ) ; EXPECT_CALL ( containerizer , launch ( _ , _ , _ , _ , _ , _ , _ ) ) . WillOnce ( Return ( Failure ( " " ) ) ) ; Future < TaskStatus > failureUpdate ; EXPECT_CALL ( sched , statusUpdate ( & driver , _ ) ) . WillOnce ( FutureArg < 1 > ( & failureUpdate ) ) ; EXPECT_CALL ( sched , executorLost ( & driver , DEFAULT_EXECUTOR_ID , _ , _ ) ) ; TaskInfo task = createTask ( offer . slave_id ( ) , Resources :: parse ( " " ) . get ( ) , " " , DEFAULT_EXECUTOR_ID ) ; driver . launchTasks ( offer . id ( ) , { task } ) ; AWAIT_READY ( failureUpdate ) ; ASSERT_EQ ( TASK_FAILED , failureUpdate . get ( ) . state ( ) ) ; snapshot = Metrics ( ) ; EXPECT_EQ ( 1 , snapshot . values [ " " ] ) ; driver . stop ( ) ; driver . join ( ) ; }
Test to verify that we increment the container launch errors metric
when we fail to launch a container.
Test to verify that we increment the container launch errors metric when we fail to launch a container .
// Start a master. // Start a slave. // Ignore subsequent offers. // Verify that we start with no launch failures. // The above injected containerizer failure also triggers executorLost. // Try to start a task // After failure injection, metrics should report a single failure.