From: wangshaohui.0512 Date: Fri, 8 Aug 2025 10:03:05 +0000 (+0800) Subject: tests: add a test case for cephfs SingletonClient X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=dd37ff462102cb0b573e8828d7295916756cfac2;p=ceph.git 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 (cherry picked from commit 8cce3277edcb819e5e61a67948f35e5c5358379d) Conflicts: src/test/client/CMakeLists.txt - syncio.cc and fscrypt_conf.cc not backported to squid --- diff --git a/src/test/client/CMakeLists.txt b/src/test/client/CMakeLists.txt index 2f4ec0171632..fbad87fa9cee 100644 --- a/src/test/client/CMakeLists.txt +++ b/src/test/client/CMakeLists.txt @@ -6,6 +6,7 @@ if(${WITH_CEPHFS}) ops.cc nonblocking.cc commands.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 000000000000..a4187a65e4f7 --- /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 000000000000..aefa56341bce --- /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); +}