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/10/28 09:50:29 UTC
mesos git commit: Fixed HealthyTaskViaHTTPWithoutType test.
Repository: mesos
Updated Branches:
refs/heads/master df25c4e9a -> 2ab0fc383
Fixed HealthyTaskViaHTTPWithoutType test.
Review: https://reviews.apache.org/r/53226
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2ab0fc38
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2ab0fc38
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2ab0fc38
Branch: refs/heads/master
Commit: 2ab0fc3835506fec913c1d027ebc2332f4d025e2
Parents: df25c4e
Author: Alexander Rukletsov <al...@apache.org>
Authored: Thu Oct 27 16:01:50 2016 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Fri Oct 28 11:50:11 2016 +0200
----------------------------------------------------------------------
src/tests/health_check_tests.cpp | 124 +++++++++++++++++++---------------
1 file changed, 68 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/2ab0fc38/src/tests/health_check_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/health_check_tests.cpp b/src/tests/health_check_tests.cpp
index b1a8942..bc3015e 100644
--- a/src/tests/health_check_tests.cpp
+++ b/src/tests/health_check_tests.cpp
@@ -1230,16 +1230,12 @@ TEST_F(HealthCheckTest, CheckCommandTimeout)
}
-// Tests a healthy task via HTTP without specifying `type`. HTTP health
-// checks without `type` are allowed for backwards compatibility with the
-// v0 and v1 API.
-//
-// TODO(haosdent): Remove this after the deprecation cycle which starts in 2.0.
-//
-// TODO(alexr): Enable this test once MESOS-6293 is resolved.
-TEST_F(HealthCheckTest, DISABLED_HealthyTaskViaHTTPWithoutType)
+// Tests the transition from healthy to unhealthy within the grace period, to
+// make sure that failures within the grace period aren't ignored if they come
+// after a success.
+TEST_F(HealthCheckTest, HealthyToUnhealthyTransitionWithinGracePeriod)
{
- master::Flags masterFlags = this->CreateMasterFlags();
+ master::Flags masterFlags = CreateMasterFlags();
masterFlags.allocation_interval = Milliseconds(50);
Try<Owned<cluster::Master>> master = StartMaster(masterFlags);
ASSERT_SOME(master);
@@ -1250,7 +1246,7 @@ TEST_F(HealthCheckTest, DISABLED_HealthyTaskViaHTTPWithoutType)
MockScheduler sched;
MesosSchedulerDriver driver(
- &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
+ &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
EXPECT_CALL(sched, registered(&driver, _, _));
@@ -1264,27 +1260,38 @@ TEST_F(HealthCheckTest, DISABLED_HealthyTaskViaHTTPWithoutType)
AWAIT_READY(offers);
EXPECT_NE(0u, offers.get().size());
- TaskInfo task = createTask(offers.get()[0], "sleep 120");
+ // Create a temporary file.
+ const string tmpPath = path::join(os::getcwd(), "healthyToUnhealthy");
- // To avoid external program dependencies, use the port of the master
- // as HTTP health check target here.
- HealthCheck healthCheck;
- healthCheck.mutable_http()->set_port(master.get()->pid.address.port);
- healthCheck.mutable_http()->set_path("/help");
- healthCheck.set_delay_seconds(0);
- healthCheck.set_interval_seconds(0);
- healthCheck.set_grace_period_seconds(0);
+ // This command fails every other invocation.
+ // For all runs i in Nat0, the following case i % 2 applies:
+ //
+ // Case 0:
+ // - Remove the temporary file.
+ //
+ // Case 1:
+ // - Attempt to remove the nonexistent temporary file.
+ // - Create the temporary file.
+ // - Exit with a non-zero status.
+ const string healthCheckCmd =
+ "rm " + tmpPath + " || (touch " + tmpPath + " && exit 1)";
- task.mutable_health_check()->CopyFrom(healthCheck);
+ // Set the grace period to 9999 seconds, so that the healthy -> unhealthy
+ // transition happens during the grace period.
+ vector<TaskInfo> tasks = populateTasks(
+ "sleep 120", healthCheckCmd, offers.get()[0], 9999, 0);
Future<TaskStatus> statusRunning;
Future<TaskStatus> statusHealthy;
+ Future<TaskStatus> statusUnhealthy;
EXPECT_CALL(sched, statusUpdate(&driver, _))
.WillOnce(FutureArg<1>(&statusRunning))
- .WillOnce(FutureArg<1>(&statusHealthy));
+ .WillOnce(FutureArg<1>(&statusHealthy))
+ .WillOnce(FutureArg<1>(&statusUnhealthy))
+ .WillRepeatedly(Return()); // Ignore subsequent updates.
- driver.launchTasks(offers.get()[0].id(), {task});
+ driver.launchTasks(offers.get()[0].id(), tasks);
AWAIT_READY(statusRunning);
EXPECT_EQ(TASK_RUNNING, statusRunning.get().state());
@@ -1294,15 +1301,18 @@ TEST_F(HealthCheckTest, DISABLED_HealthyTaskViaHTTPWithoutType)
EXPECT_TRUE(statusHealthy.get().has_healthy());
EXPECT_TRUE(statusHealthy.get().healthy());
+ AWAIT_READY(statusUnhealthy);
+ EXPECT_EQ(TASK_RUNNING, statusUnhealthy.get().state());
+ EXPECT_TRUE(statusUnhealthy.get().has_healthy());
+ EXPECT_FALSE(statusUnhealthy.get().healthy());
+
driver.stop();
driver.join();
}
-// Tests the transition from healthy to unhealthy within the grace period, to
-// make sure that failures within the grace period aren't ignored if they come
-// after a success.
-TEST_F(HealthCheckTest, HealthyToUnhealthyTransitionWithinGracePeriod)
+// Tests a healthy non-contained task via HTTP.
+TEST_F(HealthCheckTest, HealthyTaskViaHTTP)
{
master::Flags masterFlags = CreateMasterFlags();
masterFlags.allocation_interval = Milliseconds(50);
@@ -1315,7 +1325,7 @@ TEST_F(HealthCheckTest, HealthyToUnhealthyTransitionWithinGracePeriod)
MockScheduler sched;
MesosSchedulerDriver driver(
- &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
+ &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
EXPECT_CALL(sched, registered(&driver, _, _));
@@ -1329,38 +1339,39 @@ TEST_F(HealthCheckTest, HealthyToUnhealthyTransitionWithinGracePeriod)
AWAIT_READY(offers);
EXPECT_NE(0u, offers.get().size());
- // Create a temporary file.
- const string tmpPath = path::join(os::getcwd(), "healthyToUnhealthy");
+ const uint16_t testPort = 31001;
- // This command fails every other invocation.
- // For all runs i in Nat0, the following case i % 2 applies:
- //
- // Case 0:
- // - Remove the temporary file.
- //
- // Case 1:
- // - Attempt to remove the nonexistent temporary file.
- // - Create the temporary file.
- // - Exit with a non-zero status.
- const string healthCheckCmd =
- "rm " + tmpPath + " || (touch " + tmpPath + " && exit 1)";
+ // Use `test-helper` to launch a simple HTTP
+ // server to respond to HTTP health checks.
+ const string command = strings::format(
+ "%s %s --ip=127.0.0.1 --port=%u",
+ getTestHelperPath("test-helper"),
+ HealthCheckTestHelper::NAME,
+ testPort).get();
- // Set the grace period to 9999 seconds, so that the healthy -> unhealthy
- // transition happens during the grace period.
- vector<TaskInfo> tasks = populateTasks(
- "sleep 120", healthCheckCmd, offers.get()[0], 9999, 0);
+ TaskInfo task = createTask(offers.get()[0], command);
+
+ // Set `grace_period_seconds` here because it takes some time to
+ // launch the HTTP server to serve requests.
+ HealthCheck healthCheck;
+ healthCheck.set_type(HealthCheck::HTTP);
+ healthCheck.mutable_http()->set_port(testPort);
+ healthCheck.mutable_http()->set_path("/help");
+ healthCheck.set_delay_seconds(0);
+ healthCheck.set_interval_seconds(0);
+ healthCheck.set_grace_period_seconds(15);
+
+ task.mutable_health_check()->CopyFrom(healthCheck);
Future<TaskStatus> statusRunning;
Future<TaskStatus> statusHealthy;
- Future<TaskStatus> statusUnhealthy;
EXPECT_CALL(sched, statusUpdate(&driver, _))
.WillOnce(FutureArg<1>(&statusRunning))
.WillOnce(FutureArg<1>(&statusHealthy))
- .WillOnce(FutureArg<1>(&statusUnhealthy))
.WillRepeatedly(Return()); // Ignore subsequent updates.
- driver.launchTasks(offers.get()[0].id(), tasks);
+ driver.launchTasks(offers.get()[0].id(), {task});
AWAIT_READY(statusRunning);
EXPECT_EQ(TASK_RUNNING, statusRunning.get().state());
@@ -1370,18 +1381,20 @@ TEST_F(HealthCheckTest, HealthyToUnhealthyTransitionWithinGracePeriod)
EXPECT_TRUE(statusHealthy.get().has_healthy());
EXPECT_TRUE(statusHealthy.get().healthy());
- AWAIT_READY(statusUnhealthy);
- EXPECT_EQ(TASK_RUNNING, statusUnhealthy.get().state());
- EXPECT_TRUE(statusUnhealthy.get().has_healthy());
- EXPECT_FALSE(statusUnhealthy.get().healthy());
-
driver.stop();
driver.join();
}
-// Tests a healthy non-contained task via HTTP.
-TEST_F(HealthCheckTest, HealthyTaskViaHTTP)
+// Tests a healthy task via HTTP without specifying `type`. HTTP health
+// checks without `type` are allowed for backwards compatibility with the
+// v0 and v1 API.
+//
+// NOTE: This test is almost identical to HealthyTaskViaHTTP
+// with the difference being the health check type is not set.
+//
+// TODO(haosdent): Remove this after the deprecation cycle which starts in 2.0.
+TEST_F(HealthCheckTest, HealthyTaskViaHTTPWithoutType)
{
master::Flags masterFlags = CreateMasterFlags();
masterFlags.allocation_interval = Milliseconds(50);
@@ -1423,7 +1436,6 @@ TEST_F(HealthCheckTest, HealthyTaskViaHTTP)
// Set `grace_period_seconds` here because it takes some time to
// launch the HTTP server to serve requests.
HealthCheck healthCheck;
- healthCheck.set_type(HealthCheck::HTTP);
healthCheck.mutable_http()->set_port(testPort);
healthCheck.mutable_http()->set_path("/help");
healthCheck.set_delay_seconds(0);