]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
tests: add a test case for cephfs SingletonClient
authorwangshaohui.0512 <wangshaohui.0512@bytedance.com>
Fri, 8 Aug 2025 10:03:05 +0000 (18:03 +0800)
committerJos Collin <jcollin@redhat.com>
Tue, 2 Dec 2025 01:54:45 +0000 (07:24 +0530)
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 <wangshaohui.0512@bytedance.com>
(cherry picked from commit 8cce3277edcb819e5e61a67948f35e5c5358379d)

 Conflicts:
src/test/client/CMakeLists.txt
    - syncio.cc and fscrypt_conf.cc not backported to squid

src/test/client/CMakeLists.txt
src/test/client/TestPlodClient.h [new file with mode: 0644]
src/test/client/subs.cc [new file with mode: 0644]

index 2f4ec0171632692fe452777b23466bcbada32fd5..fbad87fa9cee8246df34b2109fc2435906263e24 100644 (file)
@@ -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 (file)
index 0000000..a4187a6
--- /dev/null
@@ -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<std::uint64_t>("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 (file)
index 0000000..aefa563
--- /dev/null
@@ -0,0 +1,13 @@
+#include <iostream>
+#include <errno.h>
+#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);
+}