You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2016/02/03 09:11:42 UTC

mesos git commit: Added test case for FP precision of resource allocation.

Repository: mesos
Updated Branches:
  refs/heads/master c7513a2d5 -> 910036388


Added test case for FP precision of resource allocation.

This patch is based on the commit submitted by : Mandeep (@mchadha)
https://reviews.apache.org/r/39056/

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


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

Branch: refs/heads/master
Commit: 910036388cf7e84c5611f0516462f73fc0b7abc9
Parents: c7513a2
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Wed Feb 3 09:10:58 2016 +0100
Committer: Bernd Mathiske <be...@mesosphere.io>
Committed: Wed Feb 3 09:10:58 2016 +0100

----------------------------------------------------------------------
 src/tests/reservation_tests.cpp | 101 +++++++++++++++++++++++++++++++++++
 1 file changed, 101 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/91003638/src/tests/reservation_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/reservation_tests.cpp b/src/tests/reservation_tests.cpp
index d0c8856..f50ac67 100644
--- a/src/tests/reservation_tests.cpp
+++ b/src/tests/reservation_tests.cpp
@@ -164,6 +164,107 @@ TEST_F(ReservationTest, ReserveThenUnreserve)
 }
 
 
+// This tests for failures arising from floating point precision errors during
+// processing of resource reservation requests.  The test first asks a framework
+// to send a resource reservation request in response to an offer, which updates
+// the resources in the allocator and results in resources being re-offered to
+// the framework. The framework then sends back a new resource reservation
+// request which involves a floating point value for the resources being
+// reserved, which in turn triggers a problematic floating point comparison.
+TEST_F(ReservationTest, ReserveTwiceWithDoubleValue)
+{
+  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
+  frameworkInfo.set_role("role");
+
+  master::Flags masterFlags = CreateMasterFlags();
+  masterFlags.allocation_interval = Milliseconds(5);
+
+  Try<PID<Master>> master = StartMaster(masterFlags);
+  ASSERT_SOME(master);
+
+  slave::Flags slaveFlags = CreateSlaveFlags();
+  slaveFlags.resources = "cpus:24;mem:4096";
+
+  Try<PID<Slave>> slave = StartSlave(slaveFlags);
+  ASSERT_SOME(slave);
+
+  MockScheduler sched;
+  MesosSchedulerDriver driver(
+      &sched, frameworkInfo, master.get(), DEFAULT_CREDENTIAL);
+
+  // We use the filter explicitly here so that the resources will not
+  // be filtered (default would be 5 seconods).
+  Filters filters;
+  filters.set_refuse_seconds(0);
+
+  Resources unreserved = Resources::parse("cpus:0.1;mem:512").get();
+  Resources dynamicallyReserved =
+    unreserved.flatten(
+        frameworkInfo.role(),
+        createReservationInfo(frameworkInfo.principal()));
+
+  Future<vector<Offer>> offers;
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+     .WillOnce(FutureArg<1>(&offers));
+
+  EXPECT_CALL(sched, registered(&driver, _, _));
+
+  driver.start();
+
+  AWAIT_READY(offers);
+
+  ASSERT_EQ(1u, offers.get().size());
+  Offer offer = offers.get()[0];
+
+  // In the first offer, expect an offer with unreserved resources.
+  EXPECT_TRUE(Resources(offer.resources()).contains(unreserved));
+
+  // The expectation for the next offer.
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+     .WillOnce(FutureArg<1>(&offers));
+
+  // First iteration: Reserving 0.1 CPU.
+  driver.acceptOffers({offer.id()}, {RESERVE(dynamicallyReserved)}, filters);
+
+  AWAIT_READY(offers);
+
+  ASSERT_EQ(1, offers.get().size());
+  offer = offers.get()[0];
+
+  // In the second offer, expect an offer with reserved resources.
+  EXPECT_TRUE(Resources(offer.resources()).contains(dynamicallyReserved));
+
+  // The expectation for the next offer.
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+     .WillOnce(FutureArg<1>(&offers));
+
+  // Second iteration: Reserving second 0.1 CPU.
+  driver.acceptOffers({offer.id()}, {RESERVE(dynamicallyReserved)}, filters);
+
+  // The agent should be able to calculate the remaining resources
+  // correctly at this point. If the floating point comparison on the
+  // agent isn't correct it will end up failing `CHECKS` on the agent,
+  // potentially crashing the agent. See MESOS-3552.
+  AWAIT_READY(offers);
+
+  ASSERT_EQ(1u, offers.get().size());
+  offer = offers.get()[0];
+
+  Resources reserved = Resources::parse("cpus:0.2;mem:512").get();
+  Resources finalReservation =
+    reserved.flatten(
+        frameworkInfo.role(),
+        createReservationInfo(frameworkInfo.principal()));
+
+  EXPECT_TRUE(Resources(offer.resources()).contains(finalReservation));
+
+  driver.stop();
+  driver.join();
+
+  Shutdown();
+}
+
+
 // This tests that a framework can send back a Reserve followed by a
 // LaunchTasks offer operation as a response to an offer, which
 // updates the resources in the allocator then proceeds to launch the