1 #include "include/rados/librados.h"
2 #include "include/rados/librados.hpp"
3 #include "include/utime.h"
4 #include "common/Thread.h"
5 #include "common/Clock.h"
6 #include "test/librados/test_cxx.h"
8 #include "gtest/gtest.h"
17 #include "test/librados/testcase_cxx.h"
20 using namespace librados
;
22 using std::ostringstream
;
26 static std::atomic
<bool> stop_flag
= { false };
28 class WatchNotifyTestCtx
: public WatchCtx
31 void notify(uint8_t opcode
, uint64_t ver
, bufferlist
& bl
) override
37 #pragma GCC diagnostic ignored "-Wpragmas"
38 #pragma GCC diagnostic push
39 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
41 struct WatcherUnwatcher
: public Thread
{
43 explicit WatcherUnwatcher(string
& _pool
) : pool(_pool
) {}
45 void *entry() override
{
47 connect_cluster_pp(cluster
);
50 cluster
.ioctx_create(pool
.c_str(), ioctx
);
53 WatchNotifyTestCtx watch_ctx
;
54 int r
= ioctx
.watch("foo", 0, &handle
, &watch_ctx
);
56 ioctx
.unwatch("foo", handle
);
63 typedef RadosTestParamPP WatchStress
;
65 INSTANTIATE_TEST_SUITE_P(WatchStressTests
, WatchStress
,
66 ::testing::Values("", "cache"));
68 TEST_P(WatchStress
, Stress1
) {
69 ASSERT_EQ(0, sem_init(&sem
, 0, 0));
71 std::string pool_name
= get_temp_pool_name();
72 ASSERT_EQ("", create_one_pool_pp(pool_name
, ncluster
));
74 ncluster
.ioctx_create(pool_name
.c_str(), nioctx
);
76 WatcherUnwatcher
*thr
= new WatcherUnwatcher(pool_name
);
77 thr
->create("watcher_unwatch");
78 ASSERT_EQ(0, nioctx
.create("foo", false));
80 for (unsigned i
= 0; i
< 75; ++i
) {
81 std::cerr
<< "Iteration " << i
<< std::endl
;
85 WatchNotifyTestCtx ctx
;
87 connect_cluster_pp(cluster
);
88 cluster
.ioctx_create(pool_name
.c_str(), ioctx
);
89 ASSERT_EQ(0, ioctx
.watch("foo", 0, &handle
, &ctx
));
91 bool do_blocklist
= i
% 2;
93 cluster
.test_blocklist_self(true);
94 std::cerr
<< "blocklisted" << std::endl
;
99 ASSERT_EQ(0, nioctx
.notify("foo", 0, bl2
));
102 sleep(1); // Give a change to see an incorrect notify
109 cluster
.test_blocklist_self(false);
112 ioctx
.unwatch("foo", handle
);
118 ASSERT_EQ(0, destroy_one_pool_pp(pool_name
, ncluster
));
122 #pragma GCC diagnostic pop
123 #pragma GCC diagnostic warning "-Wpragmas"