You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2016/11/22 13:49:11 UTC

[1/2] mesos git commit: Added the kill policy test helper.

Repository: mesos
Updated Branches:
  refs/heads/master d4aa38242 -> 71c82a1bc


Added the kill policy test helper.

This patch adds a test helper to facilitate the testing of `KillPolicy`.

The helper blocks until it receives a SIGTERM, then sleeps for a
configurable amount of time before finally returning EXIT_SUCCESS.

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


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

Branch: refs/heads/master
Commit: 4811ae0d22e7ec0234d7fc63d4c8bc1c5406883e
Parents: d4aa382
Author: Gast�n Kleiman <ga...@mesosphere.com>
Authored: Tue Nov 22 14:45:07 2016 +0100
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Tue Nov 22 14:48:59 2016 +0100

----------------------------------------------------------------------
 src/Makefile.am                       |  3 ++
 src/tests/CMakeLists.txt              |  1 +
 src/tests/kill_policy_test_helper.cpp | 71 ++++++++++++++++++++++++++++++
 src/tests/kill_policy_test_helper.hpp | 54 +++++++++++++++++++++++
 src/tests/test_helper_main.cpp        |  3 ++
 5 files changed, 132 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4811ae0d/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 5a47c93..5e0b840 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -999,6 +999,7 @@ libmesos_no_3rdparty_la_SOURCES +=					\
   tests/environment.hpp							\
   tests/flags.hpp							\
   tests/health_check_test_helper.hpp					\
+  tests/kill_policy_test_helper.hpp					\
   tests/limiter.hpp							\
   tests/mesos.hpp							\
   tests/mock_docker.hpp							\
@@ -1943,6 +1944,7 @@ test_helper_SOURCES =						\
   tests/active_user_test_helper.cpp				\
   tests/flags.cpp						\
   tests/health_check_test_helper.cpp				\
+  tests/kill_policy_test_helper.cpp				\
   tests/resources_utils.cpp					\
   tests/test_helper_main.cpp					\
   tests/utils.cpp						\
@@ -2118,6 +2120,7 @@ mesos_tests_SOURCES =						\
   tests/hook_tests.cpp						\
   tests/http_authentication_tests.cpp				\
   tests/http_fault_tolerance_tests.cpp				\
+  tests/kill_policy_test_helper.cpp				\
   tests/log_tests.cpp						\
   tests/logging_tests.cpp					\
   tests/main.cpp						\

http://git-wip-us.apache.org/repos/asf/mesos/blob/4811ae0d/src/tests/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index cf583ea..90b9225 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -22,6 +22,7 @@ set(TEST_HELPER_SRC
   active_user_test_helper.cpp
   flags.cpp
   health_check_test_helper.cpp
+  kill_policy_test_helper.cpp
   resources_utils.cpp
   test_helper_main.cpp
   utils.cpp

http://git-wip-us.apache.org/repos/asf/mesos/blob/4811ae0d/src/tests/kill_policy_test_helper.cpp
----------------------------------------------------------------------
diff --git a/src/tests/kill_policy_test_helper.cpp b/src/tests/kill_policy_test_helper.cpp
new file mode 100644
index 0000000..a188059
--- /dev/null
+++ b/src/tests/kill_policy_test_helper.cpp
@@ -0,0 +1,71 @@
+// 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 "tests/kill_policy_test_helper.hpp"
+
+#include <signal.h>
+#include <unistd.h>
+
+#include <cstdlib>
+#include <iostream>
+
+#include <stout/duration.hpp>
+#include <stout/os.hpp>
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+const char KillPolicyTestHelper::NAME[] = "KillPolicy";
+
+
+void sigtermHandler(int signum)
+{
+  // Ignore SIGTERM.
+  std::cerr << "Received SIGTERM" << std::endl;
+}
+
+
+KillPolicyTestHelper::Flags::Flags()
+{
+  add(&Flags::sleep_duration,
+      "sleep_duration",
+      "Number of seconds for which the helper will stay alive after having "
+      "received a SIGTERM signal.");
+}
+
+
+// This test helper blocks until it receives a SIGTERM, then sleeps
+// for a configurable amount of time before finally returning EXIT_SUCCESS.
+int KillPolicyTestHelper::execute()
+{
+  // Setup the signal handler.
+  struct sigaction action;
+  memset(&action, 0, sizeof(struct sigaction));
+  action.sa_handler = sigtermHandler;
+  sigaction(SIGTERM, &action, nullptr);
+
+  // Block the process until we get a signal.
+  pause();
+
+  os::sleep(Seconds(flags.sleep_duration));
+
+  return EXIT_SUCCESS;
+}
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/4811ae0d/src/tests/kill_policy_test_helper.hpp
----------------------------------------------------------------------
diff --git a/src/tests/kill_policy_test_helper.hpp b/src/tests/kill_policy_test_helper.hpp
new file mode 100644
index 0000000..2965110
--- /dev/null
+++ b/src/tests/kill_policy_test_helper.hpp
@@ -0,0 +1,54 @@
+// 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.
+
+#ifndef __KILL_POLICY_TEST_HELPER_HPP__
+#define __KILL_POLICY_TEST_HELPER_HPP__
+
+#include <cstdint>
+
+#include <stout/flags.hpp>
+#include <stout/subcommand.hpp>
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+class KillPolicyTestHelper : public Subcommand
+{
+public:
+  static const char NAME[];
+
+  struct Flags : public virtual flags::FlagsBase
+  {
+    Flags();
+
+    uint16_t sleep_duration;
+  };
+
+  KillPolicyTestHelper() : Subcommand(NAME) {}
+
+  Flags flags;
+
+protected:
+  virtual int execute();
+  virtual flags::FlagsBase* getFlags() { return &flags; }
+};
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __KILL_POLICY_TEST_HELPER_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/4811ae0d/src/tests/test_helper_main.cpp
----------------------------------------------------------------------
diff --git a/src/tests/test_helper_main.cpp b/src/tests/test_helper_main.cpp
index 42a8ec6..a7d511c 100644
--- a/src/tests/test_helper_main.cpp
+++ b/src/tests/test_helper_main.cpp
@@ -19,6 +19,7 @@
 
 #include "tests/active_user_test_helper.hpp"
 #include "tests/health_check_test_helper.hpp"
+#include "tests/kill_policy_test_helper.hpp"
 
 #include "tests/containerizer/memory_test_helper.hpp"
 #ifdef __linux__
@@ -28,6 +29,7 @@
 
 using mesos::internal::tests::ActiveUserTestHelper;
 using mesos::internal::tests::HealthCheckTestHelper;
+using mesos::internal::tests::KillPolicyTestHelper;
 using mesos::internal::tests::MemoryTestHelper;
 #ifdef __linux__
 using mesos::internal::tests::CapabilitiesTestHelper;
@@ -47,5 +49,6 @@ int main(int argc, char** argv)
 #endif
       new ActiveUserTestHelper(),
       new HealthCheckTestHelper(),
+      new KillPolicyTestHelper(),
       new MemoryTestHelper());
 }


[2/2] mesos git commit: Made `CommandExecutorTest.NoTransitionFromKillingToRunning` more robust.

Posted by al...@apache.org.
Made `CommandExecutorTest.NoTransitionFromKillingToRunning` more robust.

This patch makes the test use the newly introduced test helper, instead
of the more fragile `trap` shell built-in.

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


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

Branch: refs/heads/master
Commit: 71c82a1bc80df41040e58e9adf428e5fbcc5613b
Parents: 4811ae0
Author: Gast�n Kleiman <ga...@mesosphere.com>
Authored: Tue Nov 22 14:45:28 2016 +0100
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Tue Nov 22 14:49:00 2016 +0100

----------------------------------------------------------------------
 src/tests/command_executor_tests.cpp | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/71c82a1b/src/tests/command_executor_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/command_executor_tests.cpp b/src/tests/command_executor_tests.cpp
index 62a09bd..6352786 100644
--- a/src/tests/command_executor_tests.cpp
+++ b/src/tests/command_executor_tests.cpp
@@ -39,8 +39,10 @@
 
 #include "slave/containerizer/mesos/containerizer.hpp"
 
+#include "tests/kill_policy_test_helper.hpp"
 #include "tests/mesos.hpp"
 #include "tests/mock_slave.hpp"
+#include "tests/utils.hpp"
 
 using mesos::internal::master::Master;
 
@@ -256,13 +258,12 @@ TEST_P(CommandExecutorTest, NoTransitionFromKillingToRunning)
   AWAIT_READY(offers);
   EXPECT_EQ(1u, offers->size());
 
-  // Use "15" instead of SIGTERM to workaround a bug in ash's implementation of
-  // trap.
-  //
-  // TODO(gkleiman): Replace this fragile workaround with a test helper.
-  TaskInfo task = createTask(
-      offers->front(),
-      "trap \"sleep 15\" 15 && sleep 120");
+  const string command = strings::format(
+      "%s %s --sleep_duration=15",
+      getTestHelperPath("test-helper"),
+      KillPolicyTestHelper::NAME).get();
+
+  TaskInfo task = createTask(offers->front(), command);
 
   // Create a health check that succeeds until a temporary file is removed.
   Try<string> temporaryPath = os::mktemp(path::join(os::getcwd(), "XXXXXX"));