From 8cce3277edcb819e5e61a67948f35e5c5358379d Mon Sep 17 00:00:00 2001 From: "wangshaohui.0512" Date: Fri, 8 Aug 2025 18:03:05 +0800 Subject: [PATCH] tests: add a test case for cephfs SingletonClient In SingletonClient::init(), objecter->start() called before monc->authenticate(), it makes conns of monc authencated before monc->authenticate() called if mons reply faster, in this case, monc will not subsribe monmap/config. Signed-off-by: Shaohui Wang --- src/test/client/CMakeLists.txt | 1 + src/test/client/TestPlodClient.h | 84 ++++++++++++++++++++++++++++++++ src/test/client/subs.cc | 13 +++++ 3 files changed, 98 insertions(+) create mode 100644 src/test/client/TestPlodClient.h create mode 100644 src/test/client/subs.cc diff --git a/src/test/client/CMakeLists.txt b/src/test/client/CMakeLists.txt index ed233fb887db5..8b1f4a8f782f1 100644 --- a/src/test/client/CMakeLists.txt +++ b/src/test/client/CMakeLists.txt @@ -8,6 +8,7 @@ if(${WITH_CEPHFS}) commands.cc syncio.cc fscrypt_conf.cc + subs.cc ) target_link_libraries(ceph_test_client client diff --git a/src/test/client/TestPlodClient.h b/src/test/client/TestPlodClient.h new file mode 100644 index 0000000000000..a4187a65e4f78 --- /dev/null +++ b/src/test/client/TestPlodClient.h @@ -0,0 +1,84 @@ +#include "gtest/gtest.h" + +#include "common/async/context_pool.h" +#include "global/global_context.h" + +#include "msg/Messenger.h" +#include "mon/MonClient.h" +#include "osdc/ObjectCacher.h" +#include "client/MetaRequest.h" +#include "client/Client.h" +#include "messages/MClientReclaim.h" +#include "messages/MClientSession.h" +#include "common/async/blocked_completion.h" + +#define dout_subsys ceph_subsys_client + +namespace bs = boost::system; +namespace ca = ceph::async; + +class MonClientScaffold : public MonClient { +public: + MonClientScaffold(CephContext *cct_, boost::asio::io_context& service) : MonClient(cct_, service) {} + virtual ~MonClientScaffold() {} + + bool check_monmap_subed () { + return !sub_want("monmap", monmap.get_epoch() ? monmap.get_epoch() + 1 : 0, 0); + } + + bool check_config_subed () { + return !sub_want("config", 0, 0); + } +}; + +class TestPlodClient : public ::testing::Test { +public: + static void SetUpTestSuite() { + icp.start(g_ceph_context->_conf.get_val("client_asio_thread_count")); + } + static void TearDownTestSuite() { + icp.stop(); + } + void SetUp() override { + messenger = Messenger::create_client_messenger(g_ceph_context, "client"); + if (messenger->start() != 0) { + throw std::runtime_error("failed to start messenger"); + } + + mc = new MonClientScaffold(g_ceph_context, icp); + if (mc->build_initial_monmap() < 0) { + throw std::runtime_error("build monmap"); + } + mc->set_messenger(messenger); + mc->set_want_keys(CEPH_ENTITY_TYPE_MDS | CEPH_ENTITY_TYPE_OSD); + if (mc->init() < 0) { + throw std::runtime_error("init monclient"); + } + + client = new StandaloneClient(messenger, mc, icp); + client->init(); + sleep(1); + client->mount("/", myperm, true); + } + void TearDown() override { + if (client->is_mounted()) + client->unmount(); + client->shutdown(); + mc->shutdown(); + messenger->shutdown(); + messenger->wait(); + + delete client; + client = nullptr; + delete mc; + mc = nullptr; + delete messenger; + messenger = nullptr; + } +protected: + static inline ceph::async::io_context_pool icp; + static inline UserPerm myperm{0,0}; + MonClientScaffold* mc = nullptr; + Messenger* messenger = nullptr; + StandaloneClient* client = nullptr; +}; diff --git a/src/test/client/subs.cc b/src/test/client/subs.cc new file mode 100644 index 0000000000000..aefa56341bce9 --- /dev/null +++ b/src/test/client/subs.cc @@ -0,0 +1,13 @@ +#include +#include +#include "TestPlodClient.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include "gtest/gtest-spi.h" +#include "gmock/gmock-matchers.h" +#include "gmock/gmock-more-matchers.h" + +TEST_F(TestPlodClient, CheckMonSubscribed) { + ASSERT_EQ(mc->check_monmap_subed(), true); + ASSERT_EQ(mc->check_config_subed(), true); +} -- 2.39.5