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 2017/01/03 15:56:49 UTC

mesos git commit: Fixed test flakiness due to floating point conversions.

Repository: mesos
Updated Branches:
  refs/heads/master dfff3af67 -> a3949830b


Fixed test flakiness due to floating point conversions.

`FaultToleranceTest.FrameworkReregister` and
`MasterTest.FailoverAgentReregisterFirst` both examined a timestamp
value returned by an HTTP endpoint. Such values are the result of
several conversions (`double` to `string` to `JSON::Value`); this might
result in the returned value being an integer one larger/smaller than we
expect. Hence, make the comparison within an epsilon of 1.

A similar issue in `SlaveTest.StateEndpoint` was fixed in
595c929f2816b713b4c36ce1bd23a7767afe8135.

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


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

Branch: refs/heads/master
Commit: a3949830b01c4e8f6956c3182c8d0dd71880a714
Parents: dfff3af
Author: Neil Conway <ne...@gmail.com>
Authored: Tue Jan 3 16:56:07 2017 +0100
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Tue Jan 3 16:56:07 2017 +0100

----------------------------------------------------------------------
 src/tests/fault_tolerance_tests.cpp | 24 ++++++++++++++++++------
 src/tests/master_tests.cpp          | 17 ++++++++++++++---
 src/tests/slave_tests.cpp           | 18 +++++++++---------
 3 files changed, 41 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a3949830/src/tests/fault_tolerance_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/fault_tolerance_tests.cpp b/src/tests/fault_tolerance_tests.cpp
index 24747fa..b13a7e2 100644
--- a/src/tests/fault_tolerance_tests.cpp
+++ b/src/tests/fault_tolerance_tests.cpp
@@ -887,14 +887,26 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(FaultToleranceTest, FrameworkReregister)
   EXPECT_TRUE(framework.values["connected"].as<JSON::Boolean>().value);
   EXPECT_FALSE(framework.values["recovered"].as<JSON::Boolean>().value);
 
-  EXPECT_EQ(
-      static_cast<int64_t>(registerTime.secs()),
-      framework.values["registered_time"].as<JSON::Number>().as<int64_t>());
+  // Even with a paused clock, the value of `registered_time` and
+  // `reregistered_time` from the state endpoint can differ slightly
+  // from the actual start time since the value went through a number
+  // of conversions (`double` to `string` to `JSON::Value`).  Since
+  // `Clock::now` is a floating point value, the actual maximal
+  // possible difference between the real and observed value depends
+  // on both the mantissa and the exponent of the compared values; for
+  // simplicity we compare with an epsilon of `1` which allows for
+  // e.g., changes in the integer part of values close to an integer
+  // value.
+  EXPECT_NEAR(
+      registerTime.secs(),
+      framework.values["registered_time"].as<JSON::Number>().as<double>(),
+      1);
 
   ASSERT_NE(0, framework.values.count("reregistered_time"));
-  EXPECT_EQ(
-      static_cast<int64_t>(reregisterTime.secs()),
-      framework.values["reregistered_time"].as<JSON::Number>().as<int64_t>());
+  EXPECT_NEAR(
+      reregisterTime.secs(),
+      framework.values["reregistered_time"].as<JSON::Number>().as<double>(),
+      1);
 
   driver.stop();
   driver.join();

http://git-wip-us.apache.org/repos/asf/mesos/blob/a3949830/src/tests/master_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp
index 2d0cd82..f448874 100644
--- a/src/tests/master_tests.cpp
+++ b/src/tests/master_tests.cpp
@@ -5813,9 +5813,20 @@ TEST_F(MasterTest, FailoverAgentReregisterFirst)
     EXPECT_FALSE(framework.values["recovered"].as<JSON::Boolean>().value);
     EXPECT_EQ(0u, framework.values["unregistered_time"].as<JSON::Number>());
 
-    EXPECT_EQ(
-        static_cast<int64_t>(reregisterTime.secs()),
-        framework.values["registered_time"].as<JSON::Number>().as<int64_t>());
+    // Even with a paused clock, the value of `registered_time` and
+    // `reregistered_time` from the state endpoint can differ slightly
+    // from the actual start time since the value went through a
+    // number of conversions (`double` to `string` to `JSON::Value`).
+    // Since `Clock::now` is a floating point value, the actual
+    // maximal possible difference between the real and observed value
+    // depends on both the mantissa and the exponent of the compared
+    // values; for simplicity we compare with an epsilon of `1` which
+    // allows for e.g., changes in the integer part of values close to
+    // an integer value.
+    EXPECT_NEAR(
+        reregisterTime.secs(),
+        framework.values["registered_time"].as<JSON::Number>().as<double>(),
+        1);
 
     // The state endpoint does not return "reregistered_time" if it is
     // the same as "registered_time".

http://git-wip-us.apache.org/repos/asf/mesos/blob/a3949830/src/tests/slave_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_tests.cpp b/src/tests/slave_tests.cpp
index 67a6aed..d633a74 100644
--- a/src/tests/slave_tests.cpp
+++ b/src/tests/slave_tests.cpp
@@ -1495,15 +1495,15 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(SlaveTest, StateEndpoint)
   EXPECT_EQ(build::TIME, state.values["build_time"]);
   EXPECT_EQ(build::USER, state.values["build_user"]);
 
-  // Even with a paused clock, the value of `start_time` from the state endpoint
-  // can differ slightly from the actual start time since the value went through
-  // a number of conversions (`double` to `string` to `JSON::Value`).
-  // Since `Clock::now` is a floating point value, the actual maximal
-  // possible difference between the real and observed value depends
-  // on an e.g., both the mantissa and the exponent of the compared
-  // values; for simplicity we compare with an epsilon of `1` which
-  // allows for e.g., changes in the integer part of values close to
-  // an integer value.
+  // Even with a paused clock, the value of `start_time` from the
+  // state endpoint can differ slightly from the actual start time
+  // since the value went through a number of conversions (`double` to
+  // `string` to `JSON::Value`).  Since `Clock::now` is a floating
+  // point value, the actual maximal possible difference between the
+  // real and observed value depends on both the mantissa and the
+  // exponent of the compared values; for simplicity we compare with
+  // an epsilon of `1` which allows for e.g., changes in the integer
+  // part of values close to an integer value.
   ASSERT_TRUE(state.values["start_time"].is<JSON::Number>());
   EXPECT_NEAR(
       Clock::now().secs(),