You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by gi...@apache.org on 2019/07/18 16:19:15 UTC

[mesos] 07/07: Implemented `FutureTrackTest` tests.

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

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

commit f3b827fa0206715ea1242ab839c3f7c0d7f685f4
Author: Andrei Budnik <ab...@mesosphere.com>
AuthorDate: Thu Jul 18 09:10:54 2019 -0700

    Implemented `FutureTrackTest` tests.
    
    These tests verify functionality provided by the
    `PendingFutureTracker` class.
    
    Review: https://reviews.apache.org/r/71065/
---
 src/Makefile.am                           |   1 +
 src/tests/CMakeLists.txt                  |   1 +
 src/tests/common/future_tracker_tests.cpp | 148 ++++++++++++++++++++++++++++++
 3 files changed, 150 insertions(+)

diff --git a/src/Makefile.am b/src/Makefile.am
index 80ae6c0..3c600bd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2675,6 +2675,7 @@ mesos_tests_SOURCES =						\
   tests/zookeeper_test_server.hpp				\
   tests/zookeeper_url_tests.cpp					\
   tests/common/command_utils_tests.cpp				\
+  tests/common/future_tracker_tests.cpp				\
   tests/common/http_tests.cpp					\
   tests/common/recordio_tests.cpp				\
   tests/common/type_utils_tests.cpp				\
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 5eb9c65..57344a1 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -152,6 +152,7 @@ if (ENABLE_SSL)
 endif ()
 
 list(APPEND MESOS_TESTS_SRC
+  common/future_tracker_tests.cpp
   common/http_tests.cpp
   common/recordio_tests.cpp
   common/type_utils_tests.cpp)
diff --git a/src/tests/common/future_tracker_tests.cpp b/src/tests/common/future_tracker_tests.cpp
new file mode 100644
index 0000000..29d43cc
--- /dev/null
+++ b/src/tests/common/future_tracker_tests.cpp
@@ -0,0 +1,148 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include <process/gmock.hpp>
+#include <process/gtest.hpp>
+#include <process/owned.hpp>
+
+#include <stout/lambda.hpp>
+
+#include "common/future_tracker.hpp"
+
+using std::string;
+using std::vector;
+
+using process::Future;
+using process::Owned;
+using process::Promise;
+
+using testing::_;
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+class FutureTrackerTest : public ::testing::Test
+{
+protected:
+  void SetUp() override
+  {
+    Try<PendingFutureTracker*> _tracker = PendingFutureTracker::create();
+    ASSERT_FALSE(_tracker.isError());
+    tracker.reset(_tracker.get());
+  }
+
+  Owned<PendingFutureTracker> tracker;
+};
+
+
+TEST_F(FutureTrackerTest, ListPending)
+{
+  Promise<bool> promise1;
+  Promise<bool> promise2;
+
+  Future<bool> future1 = promise1.future();
+  Future<bool> future2 = promise2.future();
+
+  const FutureMetadata data1{"f1", "test1", {}};
+  const FutureMetadata data2{
+    "f2", "test2", {{"arg1", "val1"}, {"arg2", "val2"}}};
+
+  auto track1 =
+    tracker->track(future1, data1.operation, data1.component, data1.args);
+
+  auto track2 =
+    tracker->track(future2, data2.operation, data2.component, data2.args);
+
+  EXPECT_EQ(track1, future1);
+  EXPECT_EQ(track2, future2);
+
+  auto pending = tracker->pendingFutures();
+
+  AWAIT_READY(pending);
+
+  EXPECT_EQ(pending->size(), 2u);
+  EXPECT_EQ(pending->at(0), data1);
+  EXPECT_EQ(pending->at(1), data2);
+}
+
+
+TEST_F(FutureTrackerTest, ListReady)
+{
+  Promise<bool> promise1;
+  Promise<bool> promise2;
+
+  const FutureMetadata data1{"f1", "test1", {}};
+  const FutureMetadata data2{"f2", "test2", {}};
+
+  tracker->track(promise1.future(), data1.operation, data1.component);
+  tracker->track(promise2.future(), data2.operation, data2.component);
+
+  Future<Nothing> eraseFuture =
+    FUTURE_DISPATCH(_, &PendingFutureTrackerProcess::eraseFuture);
+
+  promise2.set(true);
+
+  AWAIT_READY(eraseFuture);
+
+  auto pending = tracker->pendingFutures();
+
+  AWAIT_READY(pending);
+
+  EXPECT_EQ(pending->size(), 1u);
+  EXPECT_EQ(pending->front(), data1);
+}
+
+
+TEST_F(FutureTrackerTest, ListAfterCancellation)
+{
+  vector<lambda::function<void(Owned<Promise<bool>>&)>> cancellations = {
+    [](Owned<Promise<bool>>& promise) {
+      promise->discard();
+    },
+    [](Owned<Promise<bool>>& promise) {
+      promise.reset();
+    }
+  };
+
+  for (auto& cancel : cancellations) {
+    Owned<Promise<bool>> promise(new Promise<bool>());
+
+    tracker->track(promise->future(), "f", "test");
+
+    Future<Nothing> eraseFuture =
+      FUTURE_DISPATCH(_, &PendingFutureTrackerProcess::eraseFuture);
+
+    cancel(promise);
+
+    AWAIT_READY(eraseFuture);
+
+    auto pending = tracker->pendingFutures();
+
+    AWAIT_READY(pending);
+
+    EXPECT_TRUE(pending->empty());
+  }
+}
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {