Refactored VerifyMasterLaunchTaskHook to _not_ use command executor. Review: https://reviews.apache.org/r/32948
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/66cebd3f Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/66cebd3f Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/66cebd3f Branch: refs/heads/master Commit: 66cebd3fd7666747eb5d7c7ffd31208c94d5b7da Parents: e2d6c86 Author: Niklas Nielsen <[email protected]> Authored: Mon Apr 20 14:37:37 2015 -0700 Committer: Adam B <[email protected]> Committed: Mon Apr 20 14:37:37 2015 -0700 ---------------------------------------------------------------------- src/tests/hook_tests.cpp | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/66cebd3f/src/tests/hook_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/hook_tests.cpp b/src/tests/hook_tests.cpp index 9681905..a65c0ab 100644 --- a/src/tests/hook_tests.cpp +++ b/src/tests/hook_tests.cpp @@ -129,20 +129,19 @@ TEST_F(HookTest, VerifyMasterLaunchTaskHook) Try<PID<Master>> master = StartMaster(CreateMasterFlags()); ASSERT_SOME(master); - TestContainerizer containerizer; + MockExecutor exec(DEFAULT_EXECUTOR_ID); - StandaloneMasterDetector detector(master.get()); + TestContainerizer containerizer(&exec); // Start a mock slave since we aren't testing the slave hooks yet. - MockSlave slave(CreateSlaveFlags(), &detector, &containerizer); - process::spawn(slave); + Try<PID<Slave>> slave = StartSlave(&containerizer); + ASSERT_SOME(slave); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL); - EXPECT_CALL(sched, registered(&driver, _, _)) - .Times(1); + EXPECT_CALL(sched, registered(&driver, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(&driver, _)) @@ -154,16 +153,12 @@ TEST_F(HookTest, VerifyMasterLaunchTaskHook) AWAIT_READY(offers); EXPECT_NE(0u, offers.get().size()); - CommandInfo command; - command.set_value("sleep 10"); - - // Launch a task with the command executor. TaskInfo task; task.set_name(""); task.mutable_task_id()->set_value("1"); task.mutable_slave_id()->CopyFrom(offers.get()[0].slave_id()); task.mutable_resources()->CopyFrom(offers.get()[0].resources()); - task.mutable_command()->CopyFrom(command); + task.mutable_executor()->CopyFrom(DEFAULT_EXECUTOR_INFO); // Add label which will be removed by the hook. Labels* labels = task.mutable_labels(); @@ -174,21 +169,31 @@ TEST_F(HookTest, VerifyMasterLaunchTaskHook) vector<TaskInfo> tasks; tasks.push_back(task); - Future<TaskInfo> taskInfo; - EXPECT_CALL(slave, runTask(_, _, _, _, _)) - .Times(1) - .WillOnce(FutureArg<4>(&taskInfo)); + Future<RunTaskMessage> runTaskMessage = + FUTURE_PROTOBUF(RunTaskMessage(), _, _); + + EXPECT_CALL(exec, registered(_, _, _, _)); + + EXPECT_CALL(exec, launchTask(_, _)) + .WillOnce(SendStatusUpdateFromTask(TASK_RUNNING)); + + Future<TaskStatus> status; + EXPECT_CALL(sched, statusUpdate(&driver, _)) + .WillOnce(FutureArg<1>(&status)) + .WillRepeatedly(Return()); driver.launchTasks(offers.get()[0].id(), tasks); - AWAIT_READY(taskInfo); + AWAIT_READY(runTaskMessage); + + AWAIT_READY(status); // At launchTasks, the label decorator hook inside should have been // executed and we should see the labels now. Also, verify that the // hook module has stripped the first 'testRemoveLabelKey' label. // We do this by ensuring that only one label is present and that it // is the new 'testLabelKey' label. - const Labels &labels_ = taskInfo.get().labels(); + const Labels &labels_ = runTaskMessage.get().task().labels(); ASSERT_EQ(1, labels_.labels_size()); EXPECT_EQ(labels_.labels().Get(0).key(), testLabelKey); @@ -197,9 +202,6 @@ TEST_F(HookTest, VerifyMasterLaunchTaskHook) driver.stop(); driver.join(); - process::terminate(slave); - process::wait(slave); - Shutdown(); // Must shutdown before 'containerizer' gets deallocated. }
