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.h"
8 #include "gtest/gtest.h"
17 #include "test/librados/TestCase.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_CASE_P(WatchStressTests, WatchStress,
66 ::testing::Values("", "cache"));
68 TEST_P(WatchStress, Stress1) {
69 ASSERT_NE(SEM_FAILED, (sem = sem_open("test_stress_watch", O_CREAT, 0644, 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);
75 WatchNotifyTestCtx ctx;
77 WatcherUnwatcher *thr = new WatcherUnwatcher(pool_name);
78 thr->create("watcher_unwatch");
79 ASSERT_EQ(0, nioctx.create("foo", false));
81 for (unsigned i = 0; i < 75; ++i) {
82 std::cerr << "Iteration " << i << std::endl;
86 WatchNotifyTestCtx ctx;
88 connect_cluster_pp(cluster);
89 cluster.ioctx_create(pool_name.c_str(), ioctx);
90 ASSERT_EQ(0, ioctx.watch("foo", 0, &handle, &ctx));
92 bool do_blacklist = i % 2;
94 cluster.test_blacklist_self(true);
95 std::cerr << "blacklisted" << std::endl;
100 ASSERT_EQ(0, nioctx.notify("foo", 0, bl2));
103 sleep(1); // Give a change to see an incorrect notify
110 cluster.test_blacklist_self(false);
113 ioctx.unwatch("foo", handle);
119 ASSERT_EQ(0, destroy_one_pool_pp(pool_name, ncluster));
123 #pragma GCC diagnostic pop
124 #pragma GCC diagnostic warning "-Wpragmas"