Added test case `HealthCheckTest.HealthyTaskViaHTTPWithoutType`. Review: https://reviews.apache.org/r/52301/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d7b1b667 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d7b1b667 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d7b1b667 Branch: refs/heads/master Commit: d7b1b667d8e48b0d5cf862a39c01832b2c05898d Parents: 2fe229d Author: haosdent huang <haosd...@gmail.com> Authored: Thu Sep 29 17:27:58 2016 +0200 Committer: Alexander Rukletsov <al...@apache.org> Committed: Thu Sep 29 18:30:31 2016 +0200 ---------------------------------------------------------------------- src/tests/health_check_tests.cpp | 72 +++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/d7b1b667/src/tests/health_check_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/health_check_tests.cpp b/src/tests/health_check_tests.cpp index e6b02f2..5702f45 100644 --- a/src/tests/health_check_tests.cpp +++ b/src/tests/health_check_tests.cpp @@ -1329,6 +1329,78 @@ TEST_F(HealthCheckTest, CheckCommandTimeout) driver.join(); } + +// Testing 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. +TEST_F(HealthCheckTest, HealthyTaskViaHTTPWithoutType) +{ + master::Flags masterFlags = this->CreateMasterFlags(); + masterFlags.allocation_interval = Milliseconds(50); + Try<Owned<cluster::Master>> master = StartMaster(masterFlags); + ASSERT_SOME(master); + + slave::Flags flags = CreateSlaveFlags(); + flags.isolation = "posix/cpu,posix/mem"; + + Owned<MasterDetector> detector = master.get()->createDetector(); + + Try<Owned<cluster::Slave>> agent = StartSlave(detector.get()); + ASSERT_SOME(agent); + + MockScheduler sched; + MesosSchedulerDriver driver( + &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); + + EXPECT_CALL(sched, registered(&driver, _, _)) + .Times(1); + + Future<vector<Offer>> offers; + EXPECT_CALL(sched, resourceOffers(&driver, _)) + .WillOnce(FutureArg<1>(&offers)) + .WillRepeatedly(Return()); // Ignore subsequent offers. + + driver.start(); + + AWAIT_READY(offers); + EXPECT_NE(0u, offers.get().size()); + + TaskInfo task = createTask(offers.get()[0], "sleep 120"); + + // 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); + + task.mutable_health_check()->CopyFrom(healthCheck); + + Future<TaskStatus> statusRunning; + Future<TaskStatus> statusHealth; + + EXPECT_CALL(sched, statusUpdate(&driver, _)) + .WillOnce(FutureArg<1>(&statusRunning)) + .WillOnce(FutureArg<1>(&statusHealth)); + + driver.launchTasks(offers.get()[0].id(), {task}); + + AWAIT_READY(statusRunning); + EXPECT_EQ(TASK_RUNNING, statusRunning.get().state()); + + AWAIT_READY(statusHealth); + EXPECT_EQ(TASK_RUNNING, statusHealth.get().state()); + EXPECT_TRUE(statusHealth.get().has_healthy()); + EXPECT_TRUE(statusHealth.get().healthy()); + + driver.stop(); + driver.join(); +} + } // namespace tests { } // namespace internal { } // namespace mesos {