X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Ftest%2Flibrbd%2Ftest_mock_Watcher.cc;h=b36ec3e31f2ae8b6c0c77da93d0da2a601850d2f;hb=e306af509c4d4816a1f73b17a825ea5186fa0030;hp=907f671e8771bf329e45c6a4d87abc8e913b1baf;hpb=11fdf7f228cb605e22a0e495ebabd3329db96b81;p=ceph.git diff --git a/ceph/src/test/librbd/test_mock_Watcher.cc b/ceph/src/test/librbd/test_mock_Watcher.cc index 907f671e8..b36ec3e31 100644 --- a/ceph/src/test/librbd/test_mock_Watcher.cc +++ b/ceph/src/test/librbd/test_mock_Watcher.cc @@ -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; }; @@ -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(®ister_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) {