Added a test `TaskValidationTest.TaskMissingDockerInfo`.

Review: https://reviews.apache.org/r/65917/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ac844a68
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ac844a68
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ac844a68

Branch: refs/heads/master
Commit: ac844a68c1947274c820d0e176795e66863d5a22
Parents: e7cb1d9
Author: Qian Zhang <zhq527...@gmail.com>
Authored: Mon Mar 12 19:54:21 2018 -0700
Committer: Gilbert Song <songzihao1...@gmail.com>
Committed: Mon Mar 12 22:41:05 2018 -0700

----------------------------------------------------------------------
 src/tests/master_validation_tests.cpp | 50 ++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ac844a68/src/tests/master_validation_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_validation_tests.cpp 
b/src/tests/master_validation_tests.cpp
index 53cc3ed..799da62 100644
--- a/src/tests/master_validation_tests.cpp
+++ b/src/tests/master_validation_tests.cpp
@@ -2775,6 +2775,56 @@ TEST_F(TaskValidationTest, TaskEnvironmentInvalid)
   driver.join();
 }
 
+
+// This test verifies that a task that has `ContainerInfo` set as DOCKER
+// but has no `DockerInfo` is rejected during `TaskInfo` validation.
+TEST_F(TaskValidationTest, TaskMissingDockerInfo)
+{
+  Try<Owned<cluster::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  Owned<MasterDetector> detector = master.get()->createDetector();
+  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get());
+  ASSERT_SOME(slave);
+
+  MockScheduler sched;
+  MesosSchedulerDriver driver(
+      &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
+
+  EXPECT_CALL(sched, registered(&driver, _, _));
+
+  Future<vector<Offer>> offers;
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+    .WillOnce(FutureArg<1>(&offers))
+    .WillRepeatedly(Return()); // Ignore subsequent offers.
+
+  driver.start();
+
+  AWAIT_READY(offers);
+  ASSERT_FALSE(offers->empty());
+
+  Future<TaskStatus> status;
+  EXPECT_CALL(sched, statusUpdate(&driver, _))
+    .WillOnce(FutureArg<1>(&status));
+
+  // Create an invalid task that has `ContainerInfo` set
+  // as DOCKER but has no `DockerInfo`.
+  TaskInfo task = createTask(offers.get()[0], "exit 0");
+  task.mutable_container()->set_type(ContainerInfo::DOCKER);
+
+  driver.launchTasks(offers.get()[0].id(), {task});
+
+  AWAIT_READY(status);
+  EXPECT_EQ(TASK_ERROR, status->state());
+  EXPECT_EQ(
+      "Task's `ContainerInfo` is invalid: "
+      "DockerInfo 'docker' is not set for DOCKER typed ContainerInfo",
+      status->message());
+
+  driver.stop();
+  driver.join();
+}
+
 // TODO(jieyu): Add tests for checking duplicated persistence ID
 // against offered resources.
 

Reply via email to