You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ch...@apache.org on 2018/07/13 21:41:10 UTC

[05/17] mesos git commit: Declined unwanted offers in `RetryOperationStatusUpdate*` SLRP tests.

Declined unwanted offers in `RetryOperationStatusUpdate*` SLRP tests.

The two SLRP tests assume that SLRP will send out a RAW resource in its
first `UPDATE_STATE` message, and expect that the test framework would
receive an offer containing the RAW resource in its first offer. However
this behavior is not guaranteed and should not be relied on. This patch
makes the tests decline unwanted offers by default so they no longer
rely on SLRP's internal behavior.

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


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

Branch: refs/heads/master
Commit: 141868644cd7d683511dedd125b8a1680ff33cb0
Parents: c2bdf07
Author: Chun-Hung Hsiao <ch...@mesosphere.io>
Authored: Thu Mar 8 15:09:33 2018 -0800
Committer: Chun-Hung Hsiao <ch...@mesosphere.io>
Committed: Fri Jul 13 14:30:06 2018 -0700

----------------------------------------------------------------------
 .../storage_local_resource_provider_tests.cpp   | 60 ++++++++++++--------
 1 file changed, 36 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/14186864/src/tests/storage_local_resource_provider_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/storage_local_resource_provider_tests.cpp b/src/tests/storage_local_resource_provider_tests.cpp
index 1afe8a8..a4398e0 100644
--- a/src/tests/storage_local_resource_provider_tests.cpp
+++ b/src/tests/storage_local_resource_provider_tests.cpp
@@ -2535,20 +2535,32 @@ TEST_F(StorageLocalResourceProviderTest, ROOT_RetryOperationStatusUpdate)
 
   Future<vector<Offer>> offers;
 
-  auto isRaw = [](
-      const Resource& r) {
+  // Decline offers without RAW disk resources. The master can send such offers
+  // before the resource provider reports its RAW resources, or after receiving
+  // the `UpdateOperationStatusMessage`.
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+    .WillRepeatedly(DeclineOffers());
+
+  auto isRaw = [](const Resource& r) {
     return r.has_disk() &&
       r.disk().has_source() &&
       r.disk().source().has_profile() &&
       r.disk().source().type() == Resource::DiskInfo::Source::RAW;
   };
 
-  EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
-      std::bind(isRaw, lambda::_1))))
+  EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(isRaw)))
     .WillOnce(FutureArg<1>(&offers));
 
   driver.start();
 
+  // NOTE: If the framework has not declined an unwanted offer yet when the
+  // resource provider reports its RAW resources, the new allocation triggered
+  // by this update won't generate an allocatable offer due to no CPU and memory
+  // resources. So we first settle the clock to ensure that the unwanted offer
+  // has been declined, then advance the clock to trigger another allocation.
+  Clock::settle();
+  Clock::advance(masterFlags.allocation_interval);
+
   AWAIT_READY(offers);
   ASSERT_FALSE(offers->empty());
 
@@ -2597,12 +2609,6 @@ TEST_F(StorageLocalResourceProviderTest, ROOT_RetryOperationStatusUpdate)
   // send further operation status updates.
   EXPECT_NO_FUTURE_PROTOBUFS(UpdateOperationStatusMessage(), _, _);
 
-  // The master received the `UpdateOperationStatusMessage`, so it can now
-  // offer the `MOUNT` disk - no further offers are needed, so they can be
-  // declined.
-  EXPECT_CALL(sched, resourceOffers(&driver, _))
-    .WillRepeatedly(DeclineOffers());
-
   Clock::advance(slave::STATUS_UPDATE_RETRY_INTERVAL_MIN);
   Clock::settle();
 
@@ -2686,20 +2692,32 @@ TEST_F(
 
   Future<vector<Offer>> offers;
 
-  auto isRaw = [](
-      const Resource& r) {
+  // Decline offers without RAW disk resources. The master can send such offers
+  // before the resource provider reports its RAW resources, or after receiving
+  // the `UpdateOperationStatusMessage`.
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+    .WillRepeatedly(DeclineOffers());
+
+  auto isRaw = [](const Resource& r) {
     return r.has_disk() &&
       r.disk().has_source() &&
       r.disk().source().has_profile() &&
       r.disk().source().type() == Resource::DiskInfo::Source::RAW;
   };
 
-  EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
-      std::bind(isRaw, lambda::_1))))
+  EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(isRaw)))
     .WillOnce(FutureArg<1>(&offers));
 
   driver.start();
 
+  // NOTE: If the framework has not declined an unwanted offer yet when the
+  // resource provider reports its RAW resources, the new allocation triggered
+  // by this update won't generate an allocatable offer due to no CPU and memory
+  // resources. So we first settle the clock to ensure that the unwanted offer
+  // has been declined, then advance the clock to trigger another allocation.
+  Clock::settle();
+  Clock::advance(masterFlags.allocation_interval);
+
   AWAIT_READY(offers);
   ASSERT_FALSE(offers->empty());
 
@@ -2749,12 +2767,6 @@ TEST_F(
   Future<AcknowledgeOperationStatusMessage> acknowledgeOperationStatusMessage =
     FUTURE_PROTOBUF(AcknowledgeOperationStatusMessage(), master.get()->pid, _);
 
-  // Decline offers without RAW disk resources, the master can send such offers
-  // once it receives the first `UpdateSlaveMessage` after the agent failover,
-  // or after receiving the `UpdateOperationStatusMessage`.
-  EXPECT_CALL(sched, resourceOffers(&driver, _))
-    .WillRepeatedly(DeclineOffers());
-
   slave = StartSlave(detector.get(), flags);
   ASSERT_SOME(slave);
 
@@ -3701,8 +3713,8 @@ TEST_F(
       r.disk().source().type() == v1::Resource::DiskInfo::Source::RAW;
   };
 
-  EXPECT_CALL(*scheduler, offers(_, v1::scheduler::OffersHaveAnyResource(
-      std::bind(isRaw, lambda::_1))))
+  EXPECT_CALL(
+      *scheduler, offers(_, v1::scheduler::OffersHaveAnyResource(isRaw)))
     .WillOnce(FutureArg<1>(&offers));
 
   v1::scheduler::TestMesos mesos(
@@ -3886,8 +3898,8 @@ TEST_F(
       r.disk().source().type() == v1::Resource::DiskInfo::Source::RAW;
   };
 
-  EXPECT_CALL(*scheduler, offers(_, v1::scheduler::OffersHaveAnyResource(
-      std::bind(isRaw, lambda::_1))))
+  EXPECT_CALL(
+      *scheduler, offers(_, v1::scheduler::OffersHaveAnyResource(isRaw)))
     .WillOnce(FutureArg<1>(&offers));
 
   v1::scheduler::TestMesos mesos(