You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2016/04/25 23:32:34 UTC
[41/50] mesos git commit: Fixed flaky
MaxCompletedTasksPerFrameworkFlag test.
Fixed flaky MaxCompletedTasksPerFrameworkFlag test.
Previously, this test was calling EXPECT_CALL() on
SchedulerDriver.resourceOffers() after the scheduler driver itself had
already been started. This resulted in flaky test results when offers
came in between schedDriver.start() and the EXPECT_CALL().
This commit fixes this test by moving the EXPECT_CALL() above the
schedDriver.start() call. However, because of the nature of this test,
this introduced a few complexities related to processing the incoming offers
in a loop later on. To allow this, we had to introduce a custom gmock
ACTION to enqueue offers in a process::Queue for later processing. This
ACTION is generally useful and has been placed in src/tests/mesos.hpp.
Review: https://reviews.apache.org/r/42921/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d3108d77
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d3108d77
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d3108d77
Branch: refs/heads/0.26.x
Commit: d3108d776b6f7121e37176eda686ecc7245be4cd
Parents: daada4f
Author: Kevin Klues <kl...@gmail.com>
Authored: Fri Jan 29 13:14:20 2016 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Fri Feb 26 20:59:07 2016 -0800
----------------------------------------------------------------------
src/tests/master_tests.cpp | 20 +++++++++-----------
src/tests/mesos.hpp | 14 ++++++++++++++
2 files changed, 23 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/d3108d77/src/tests/master_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp
index c3beb09..b734867 100644
--- a/src/tests/master_tests.cpp
+++ b/src/tests/master_tests.cpp
@@ -4048,25 +4048,23 @@ TEST_F(MasterTest, MaxCompletedTasksPerFrameworkFlag)
EXPECT_CALL(sched, registered(_, _, _))
.WillOnce(FutureSatisfy(&schedRegistered));
+ process::Queue<Offer> offers;
+ EXPECT_CALL(sched, resourceOffers(_, _))
+ .WillRepeatedly(EnqueueOffers(&offers));
+
schedDriver.start();
AWAIT_READY(schedRegistered);
for (size_t i = 0; i < totalTasksPerFramework; i++) {
- Future<vector<Offer>> offers;
- EXPECT_CALL(sched, resourceOffers(&schedDriver, _))
- .WillOnce(FutureArg<1>(&offers))
- .WillRepeatedly(Return());
-
- AWAIT_READY(offers);
- EXPECT_NE(0u, offers->size());
- Offer offer = offers.get()[0];
+ Future<Offer> offer = offers.get();
+ AWAIT_READY(offer);
TaskInfo task;
task.set_name("");
task.mutable_task_id()->set_value(stringify(i));
- task.mutable_slave_id()->MergeFrom(offer.slave_id());
- task.mutable_resources()->MergeFrom(offer.resources());
+ task.mutable_slave_id()->MergeFrom(offer->slave_id());
+ task.mutable_resources()->MergeFrom(offer->resources());
task.mutable_executor()->MergeFrom(DEFAULT_EXECUTOR_INFO);
// Make sure the task passes through its TASK_FINISHED
@@ -4078,7 +4076,7 @@ TEST_F(MasterTest, MaxCompletedTasksPerFrameworkFlag)
EXPECT_CALL(sched, statusUpdate(_, _))
.WillOnce(FutureArg<1>(&statusFinished));
- schedDriver.launchTasks(offer.id(), {task});
+ schedDriver.launchTasks(offer->id(), {task});
AWAIT_READY(statusFinished);
EXPECT_EQ(TASK_FINISHED, statusFinished->state());
http://git-wip-us.apache.org/repos/asf/mesos/blob/d3108d77/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 25074a0..6014294 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -674,6 +674,20 @@ ACTION_P(DeclineOffers, filters)
}
+// For use with a MockScheduler, for example:
+// process::Queue<Offer> offers;
+// EXPECT_CALL(sched, resourceOffers(_, _))
+// .WillRepeatedly(EnqueueOffers(&offers));
+// Enqueues all received offers into the provided queue.
+ACTION_P(EnqueueOffers, queue)
+{
+ std::vector<Offer> offers = arg1;
+ foreach (const Offer& offer, offers) {
+ queue->put(offer);
+ }
+}
+
+
// Definition of a mock Executor to be used in tests with gmock.
class MockExecutor : public Executor
{