Skip to content

Commit 8cce327

Browse files
wangshaohui.0512vshankar
authored andcommitted
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 <[email protected]>
1 parent b5ebfaf commit 8cce327

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

src/test/client/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if(${WITH_CEPHFS})
88
commands.cc
99
syncio.cc
1010
fscrypt_conf.cc
11+
subs.cc
1112
)
1213
target_link_libraries(ceph_test_client
1314
client

src/test/client/TestPlodClient.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#include "gtest/gtest.h"
2+
3+
#include "common/async/context_pool.h"
4+
#include "global/global_context.h"
5+
6+
#include "msg/Messenger.h"
7+
#include "mon/MonClient.h"
8+
#include "osdc/ObjectCacher.h"
9+
#include "client/MetaRequest.h"
10+
#include "client/Client.h"
11+
#include "messages/MClientReclaim.h"
12+
#include "messages/MClientSession.h"
13+
#include "common/async/blocked_completion.h"
14+
15+
#define dout_subsys ceph_subsys_client
16+
17+
namespace bs = boost::system;
18+
namespace ca = ceph::async;
19+
20+
class MonClientScaffold : public MonClient {
21+
public:
22+
MonClientScaffold(CephContext *cct_, boost::asio::io_context& service) : MonClient(cct_, service) {}
23+
virtual ~MonClientScaffold() {}
24+
25+
bool check_monmap_subed () {
26+
return !sub_want("monmap", monmap.get_epoch() ? monmap.get_epoch() + 1 : 0, 0);
27+
}
28+
29+
bool check_config_subed () {
30+
return !sub_want("config", 0, 0);
31+
}
32+
};
33+
34+
class TestPlodClient : public ::testing::Test {
35+
public:
36+
static void SetUpTestSuite() {
37+
icp.start(g_ceph_context->_conf.get_val<std::uint64_t>("client_asio_thread_count"));
38+
}
39+
static void TearDownTestSuite() {
40+
icp.stop();
41+
}
42+
void SetUp() override {
43+
messenger = Messenger::create_client_messenger(g_ceph_context, "client");
44+
if (messenger->start() != 0) {
45+
throw std::runtime_error("failed to start messenger");
46+
}
47+
48+
mc = new MonClientScaffold(g_ceph_context, icp);
49+
if (mc->build_initial_monmap() < 0) {
50+
throw std::runtime_error("build monmap");
51+
}
52+
mc->set_messenger(messenger);
53+
mc->set_want_keys(CEPH_ENTITY_TYPE_MDS | CEPH_ENTITY_TYPE_OSD);
54+
if (mc->init() < 0) {
55+
throw std::runtime_error("init monclient");
56+
}
57+
58+
client = new StandaloneClient(messenger, mc, icp);
59+
client->init();
60+
sleep(1);
61+
client->mount("/", myperm, true);
62+
}
63+
void TearDown() override {
64+
if (client->is_mounted())
65+
client->unmount();
66+
client->shutdown();
67+
mc->shutdown();
68+
messenger->shutdown();
69+
messenger->wait();
70+
71+
delete client;
72+
client = nullptr;
73+
delete mc;
74+
mc = nullptr;
75+
delete messenger;
76+
messenger = nullptr;
77+
}
78+
protected:
79+
static inline ceph::async::io_context_pool icp;
80+
static inline UserPerm myperm{0,0};
81+
MonClientScaffold* mc = nullptr;
82+
Messenger* messenger = nullptr;
83+
StandaloneClient* client = nullptr;
84+
};

src/test/client/subs.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <iostream>
2+
#include <errno.h>
3+
#include "TestPlodClient.h"
4+
#include "gmock/gmock.h"
5+
#include "gtest/gtest.h"
6+
#include "gtest/gtest-spi.h"
7+
#include "gmock/gmock-matchers.h"
8+
#include "gmock/gmock-more-matchers.h"
9+
10+
TEST_F(TestPlodClient, CheckMonSubscribed) {
11+
ASSERT_EQ(mc->check_monmap_subed(), true);
12+
ASSERT_EQ(mc->check_config_subed(), true);
13+
}

0 commit comments

Comments
 (0)