]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/test/librbd/test_mock_Watcher.cc
import 15.2.4
[ceph.git] / ceph / src / test / librbd / test_mock_Watcher.cc
index 41797c6997a5e205ea03dffed3002651b752da76..b36ec3e31f2ae8b6c0c77da93d0da2a601850d2f 100644 (file)
@@ -7,7 +7,7 @@
 #include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
 #include "test/librados_test_stub/MockTestMemRadosClient.h"
 #include "common/Cond.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
 #include "librados/AioCompletionImpl.h"
 #include "librbd/Watcher.h"
 #include "librbd/watcher/RewatchRequest.h"
@@ -38,6 +38,7 @@ struct MockWatcher : public Watcher {
 namespace librbd {
 
 using ::testing::_;
+using ::testing::DoAll;
 using ::testing::DoDefault;
 using ::testing::Invoke;
 using ::testing::InSequence;
@@ -48,8 +49,7 @@ using ::testing::WithArgs;
 
 class TestMockWatcher : public TestMockFixture {
 public:
-  TestMockWatcher() : m_lock("TestMockWatcher::m_lock") {
-  }
+  TestMockWatcher() =  default;
 
   virtual void SetUp() {
     TestMockFixture::SetUp();
@@ -76,7 +76,7 @@ public:
           }
 
           c->get();
-          mock_image_ctx.image_ctx->op_work_queue->queue(new FunctionContext([mock_rados_client, action, c](int r) {
+          mock_image_ctx.image_ctx->op_work_queue->queue(new LambdaContext([mock_rados_client, action, c](int r) {
               if (action) {
                 action();
               }
@@ -97,7 +97,7 @@ public:
       .WillOnce(DoAll(Invoke([this, &mock_image_ctx, mock_rados_client, r, action](
               uint64_t handle, librados::AioCompletionImpl *c) {
           c->get();
-          mock_image_ctx.image_ctx->op_work_queue->queue(new FunctionContext([mock_rados_client, action, c](int r) {
+          mock_image_ctx.image_ctx->op_work_queue->queue(new LambdaContext([mock_rados_client, action, c](int r) {
               if (action) {
                 action();
               }
@@ -112,15 +112,15 @@ public:
   librados::WatchCtx2 *m_watch_ctx = nullptr;
 
   void notify_watch() {
-    Mutex::Locker locker(m_lock);
+    std::lock_guard locker{m_lock};
     ++m_watch_count;
-    m_cond.Signal();
+    m_cond.notify_all();
   }
 
   bool wait_for_watch(MockImageCtx &mock_image_ctx, size_t count) {
-    Mutex::Locker locker(m_lock);
+    std::unique_lock locker{m_lock};
     while (m_watch_count < count) {
-      if (m_cond.WaitInterval(m_lock, utime_t(10, 0)) != 0) {
+      if (m_cond.wait_for(locker, 10s) == std::cv_status::timeout) {
         return false;
       }
     }
@@ -128,8 +128,8 @@ public:
     return true;
   }
 
-  Mutex m_lock;
-  Cond m_cond;
+  ceph::mutex m_lock = ceph::make_mutex("TestMockWatcher::m_lock");
+  ceph::condition_variable m_cond;
   size_t m_watch_count = 0;
 };
 
@@ -207,7 +207,7 @@ TEST_F(TestMockWatcher, Reregister) {
   mock_image_watcher.register_watch(&register_ctx);
   ASSERT_EQ(0, register_ctx.wait());
 
-  assert(m_watch_ctx != nullptr);
+  ceph_assert(m_watch_ctx != nullptr);
   m_watch_ctx->handle_error(0, -ESHUTDOWN);
 
   // wait for recovery unwatch/watch
@@ -237,7 +237,7 @@ TEST_F(TestMockWatcher, ReregisterUnwatchError) {
   mock_image_watcher.register_watch(&register_ctx);
   ASSERT_EQ(0, register_ctx.wait());
 
-  assert(m_watch_ctx != nullptr);
+  ceph_assert(m_watch_ctx != nullptr);
   m_watch_ctx->handle_error(0, -ESHUTDOWN);
 
   // wait for recovery unwatch/watch
@@ -268,7 +268,7 @@ TEST_F(TestMockWatcher, ReregisterWatchError) {
   mock_image_watcher.register_watch(&register_ctx);
   ASSERT_EQ(0, register_ctx.wait());
 
-  assert(m_watch_ctx != nullptr);
+  ceph_assert(m_watch_ctx != nullptr);
   m_watch_ctx->handle_error(0, -ESHUTDOWN);
 
   // wait for recovery unwatch/watch
@@ -293,12 +293,6 @@ TEST_F(TestMockWatcher, ReregisterWatchBlacklist) {
   expect_aio_unwatch(mock_image_ctx, 0);
   expect_aio_watch(mock_image_ctx, -EBLACKLISTED);
 
-  C_SaferCond blacklist_ctx;
-  expect_aio_watch(mock_image_ctx, 0, [&blacklist_ctx]() {
-      blacklist_ctx.wait();
-    });
-  expect_aio_unwatch(mock_image_ctx, 0);
-
   C_SaferCond register_ctx;
   mock_image_watcher.register_watch(&register_ctx);
   ASSERT_TRUE(wait_for_watch(mock_image_ctx, 1));
@@ -309,17 +303,11 @@ TEST_F(TestMockWatcher, ReregisterWatchBlacklist) {
 
   // wait for recovery unwatch/watch
   ASSERT_TRUE(wait_for_watch(mock_image_ctx, 2));
-
   ASSERT_TRUE(mock_image_watcher.is_blacklisted());
-  blacklist_ctx.complete(0);
-
-  // wait for post-blacklist recovery watch
-  ASSERT_TRUE(wait_for_watch(mock_image_ctx, 1));
 
   C_SaferCond unregister_ctx;
   mock_image_watcher.unregister_watch(&unregister_ctx);
   ASSERT_EQ(0, unregister_ctx.wait());
-  ASSERT_FALSE(mock_image_watcher.is_blacklisted());
 }
 
 TEST_F(TestMockWatcher, ReregisterUnwatchPendingUnregister) {
@@ -345,7 +333,7 @@ TEST_F(TestMockWatcher, ReregisterUnwatchPendingUnregister) {
   mock_image_watcher.register_watch(&register_ctx);
   ASSERT_EQ(0, register_ctx.wait());
 
-  assert(m_watch_ctx != nullptr);
+  ceph_assert(m_watch_ctx != nullptr);
   m_watch_ctx->handle_error(0, -EBLACKLISTED);
 
   ASSERT_EQ(0, unregister_ctx.wait());
@@ -375,7 +363,7 @@ TEST_F(TestMockWatcher, ReregisterWatchPendingUnregister) {
   mock_image_watcher.register_watch(&register_ctx);
   ASSERT_EQ(0, register_ctx.wait());
 
-  assert(m_watch_ctx != nullptr);
+  ceph_assert(m_watch_ctx != nullptr);
   m_watch_ctx->handle_error(0, -ESHUTDOWN);
 
   ASSERT_EQ(0, unregister_ctx.wait());
@@ -407,7 +395,7 @@ TEST_F(TestMockWatcher, ReregisterPendingUnregister) {
   mock_image_watcher.register_watch(&register_ctx);
   ASSERT_EQ(0, register_ctx.wait());
 
-  assert(m_watch_ctx != nullptr);
+  ceph_assert(m_watch_ctx != nullptr);
   m_watch_ctx->handle_error(0, -ESHUTDOWN);
 
   ASSERT_EQ(0, unregister_ctx.wait());