This is an automated email from the ASF dual-hosted git repository.

bennoe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit af2c47a5e680b5c3140fd7d4639750f476f1627c
Author: Benno Evers <[email protected]>
AuthorDate: Thu Mar 7 17:51:22 2019 +0100

    Added helper to test for metrics values.
    
    This patch adds a new helper function to check
    whether a given metric has some specified value.
    
    Review: https://reviews.apache.org/r/70156
---
 src/tests/utils.hpp | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/tests/utils.hpp b/src/tests/utils.hpp
index b2f22cd..0f11caf 100644
--- a/src/tests/utils.hpp
+++ b/src/tests/utils.hpp
@@ -31,8 +31,23 @@ namespace tests {
 
 // Get the metrics snapshot.
 // TODO(vinod): Move this into a libprocess utility header.
+// TODO(bevers): Rename this to `getMetrics()`.
 JSON::Object Metrics();
 
+template<typename T>
+bool metricEquals(const std::string& metric, const T& value) {
+  JSON::Object metrics = Metrics();
+
+  // NOTE: We can assume `JSON::Number` because all our
+  // metric classes (counters, gauges) do return numbers.
+  const Result<JSON::Number>& result = metrics.at<JSON::Number>(metric);
+  if (!result.isSome()) {
+    return false;
+  }
+
+  return result->as<T>() == value;
+}
+
 // Path finding utilities.
 //
 // Various tests need to access paths to load files or libraries. Normally,

Reply via email to