You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/10/22 06:20:27 UTC

[4/4] mesos git commit: Added tests for rlimits isolator.

Added tests for rlimits isolator.

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


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

Branch: refs/heads/master
Commit: a61c44540cab2338847c8ceec6ef5f0ef964e1dd
Parents: d91f134
Author: Benjamin Bannier <be...@mesosphere.io>
Authored: Fri Oct 21 22:57:49 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Fri Oct 21 23:18:31 2016 -0700

----------------------------------------------------------------------
 src/Makefile.am                                 |   1 +
 .../posix_rlimits_isolator_tests.cpp            | 128 +++++++++++++++++++
 2 files changed, 129 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a61c4454/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index b02e96d..769e998 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2174,6 +2174,7 @@ mesos_tests_SOURCES =						\
   tests/containerizer/memory_test_helper.cpp			\
   tests/containerizer/mesos_containerizer_tests.cpp		\
   tests/containerizer/mesos_containerizer_paths_tests.cpp	\
+  tests/containerizer/posix_rlimits_isolator_tests.cpp		\
   tests/containerizer/provisioner_appc_tests.cpp		\
   tests/containerizer/provisioner_backend_tests.cpp		\
   tests/containerizer/provisioner_docker_tests.cpp		\

http://git-wip-us.apache.org/repos/asf/mesos/blob/a61c4454/src/tests/containerizer/posix_rlimits_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/posix_rlimits_isolator_tests.cpp b/src/tests/containerizer/posix_rlimits_isolator_tests.cpp
new file mode 100644
index 0000000..c20e7fb
--- /dev/null
+++ b/src/tests/containerizer/posix_rlimits_isolator_tests.cpp
@@ -0,0 +1,128 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <string>
+#include <vector>
+
+#include <gmock/gmock.h>
+
+#include <process/future.hpp>
+#include <process/gtest.hpp>
+#include <process/owned.hpp>
+
+#include <stout/gtest.hpp>
+#include <stout/try.hpp>
+
+#include <mesos/master/detector.hpp>
+
+#include <mesos/mesos.hpp>
+#include <mesos/scheduler.hpp>
+
+#include "slave/flags.hpp"
+#include "tests/cluster.hpp"
+#include "tests/environment.hpp"
+#include "tests/mesos.hpp"
+
+using mesos::master::detector::MasterDetector;
+
+using process::Future;
+using process::Owned;
+
+using std::string;
+using std::vector;
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+class PosixRLimitsIsolatorTest : public MesosTest {};
+
+
+// This test confirms that if a task exceeds configured resource
+// limits it is forcibly terminated.
+TEST_F(PosixRLimitsIsolatorTest, TaskExceedingLimit)
+{
+  Try<Owned<cluster::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  slave::Flags flags = CreateSlaveFlags();
+  flags.isolation = "posix/rlimits";
+
+  Owned<MasterDetector> detector = master.get()->createDetector();
+
+  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), flags);
+  ASSERT_SOME(slave);
+
+  MockScheduler sched;
+
+  MesosSchedulerDriver driver(
+      &sched,
+      DEFAULT_FRAMEWORK_INFO,
+      master.get()->pid,
+      DEFAULT_CREDENTIAL);
+
+  EXPECT_CALL(sched, registered(_, _, _))
+    .Times(1);
+
+  Future<vector<Offer>> offers;
+  EXPECT_CALL(sched, resourceOffers(_, _))
+      .WillOnce(FutureArg<1>(&offers))
+      .WillRepeatedly(Return()); // Ignore subsequent offers.
+
+  driver.start();
+
+  AWAIT_READY(offers);
+  ASSERT_NE(0u, offers->size());
+
+  TaskInfo task = createTask(
+      offers.get()[0].slave_id(),
+      offers.get()[0].resources(),
+      "dd if=/dev/zero of=file bs=1024 count=8");
+
+  ContainerInfo* container = task.mutable_container();
+  container->set_type(ContainerInfo::MESOS);
+
+  RLimitInfo rlimitInfo;
+  RLimitInfo::RLimit* cpuLimit = rlimitInfo.add_rlimits();
+  cpuLimit->set_type(RLimitInfo::RLimit::RLMT_FSIZE);
+  cpuLimit->set_soft(1024);
+  cpuLimit->set_hard(1024);
+
+  container->mutable_rlimit_info()->CopyFrom(rlimitInfo);
+
+  Future<TaskStatus> statusRunning;
+  Future<TaskStatus> statusFailed;
+  EXPECT_CALL(sched, statusUpdate(&driver, _))
+    .WillOnce(FutureArg<1>(&statusRunning))
+    .WillOnce(FutureArg<1>(&statusFailed));
+
+  driver.launchTasks(offers.get()[0].id(), {task});
+
+  AWAIT_READY(statusRunning);
+  EXPECT_EQ(task.task_id(), statusRunning->task_id());
+  EXPECT_EQ(TASK_RUNNING, statusRunning->state());
+
+  AWAIT_READY(statusFailed);
+  EXPECT_EQ(task.task_id(), statusFailed->task_id());
+  EXPECT_EQ(TASK_FAILED, statusFailed->state());
+
+  driver.stop();
+  driver.join();
+}
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {