]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tests: LibRadosWatchNotifyPP.WatchNotify - reconnect on watch terminate 46499/head
authorNitzanMordhai <nmordech@redhat.com>
Mon, 11 Apr 2022 11:17:54 +0000 (11:17 +0000)
committerNitzan Mordechai <nmordech@redhat.com>
Thu, 2 Jun 2022 09:38:06 +0000 (12:38 +0300)
When socket failure injection or any delay that time out watch we need reconnect the watch
using the error callback to reconnect

Fixes: https://tracker.ceph.com/issues/47025
Signed-off-by: Nitzan Mordechai <nmordec@redhat.com>
(cherry picked from commit d2c5d7a4bfd58455bf99f2b3506339ce99493ce2)

src/test/librados/watch_notify_cxx.cc

index 624f417dad19419a215170c6dcbf1d72aabab982..0a145addd1f42fe414a0753218e70a24ef6a1294 100644 (file)
@@ -33,6 +33,7 @@ protected:
   int notify_err = 0;
 
   friend class WatchNotifyTestCtx2;
+  friend class WatchNotifyTestCtx2TimeOut;
 };
 
 IoCtx *notify_ioctx;
@@ -59,6 +60,41 @@ public:
     notify_ioctx->notify_ack(notify->notify_oid, notify_id, cookie, reply);
   }
 
+  void handle_error(uint64_t cookie, int err) override {
+    std::cout << __func__ << " cookie " << cookie
+             << " err " << err << std::endl;
+    ceph_assert(cookie > 1000);
+    notify_ioctx->unwatch2(cookie);
+    notify->notify_cookies.erase(cookie);
+    notify->notify_err = notify_ioctx->watch2(notify->notify_oid, &cookie, this);
+    if (notify->notify_err < err ) {
+      std::cout << "reconnect notify_err " << notify->notify_err << " err " << err << std::endl;
+    }
+  }
+};
+
+class WatchNotifyTestCtx2TimeOut : public WatchCtx2
+{
+  LibRadosWatchNotifyPP *notify;
+
+public:
+  WatchNotifyTestCtx2TimeOut(LibRadosWatchNotifyPP *notify)
+    : notify(notify)
+  {}
+
+  void handle_notify(uint64_t notify_id, uint64_t cookie, uint64_t notifier_gid,
+                    bufferlist& bl) override {
+    std::cout << __func__ << " cookie " << cookie << " notify_id " << notify_id
+             << " notifier_gid " << notifier_gid << std::endl;
+    notify->notify_bl = bl;
+    notify->notify_cookies.insert(cookie);
+    bufferlist reply;
+    reply.append("reply", 5);
+    if (notify_sleep)
+      sleep(notify_sleep);
+    notify_ioctx->notify_ack(notify->notify_oid, notify_id, cookie, reply);
+  }
+
   void handle_error(uint64_t cookie, int err) override {
     std::cout << __func__ << " cookie " << cookie
              << " err " << err << std::endl;
@@ -302,7 +338,7 @@ TEST_P(LibRadosWatchNotifyPP, WatchNotify2Timeout) {
   bl1.append(buf, sizeof(buf));
   ASSERT_EQ(0, ioctx.write(notify_oid, bl1, sizeof(buf), 0));
   uint64_t handle;
-  WatchNotifyTestCtx2 ctx(this);
+  WatchNotifyTestCtx2TimeOut ctx(this);
   ASSERT_EQ(0, ioctx.watch2(notify_oid, &handle, &ctx));
   ASSERT_GT(ioctx.watch_check(handle), 0);
   std::list<obj_watch_t> watches;
@@ -337,7 +373,7 @@ TEST_P(LibRadosWatchNotifyPP, WatchNotify3) {
   bl1.append(buf, sizeof(buf));
   ASSERT_EQ(0, ioctx.write(notify_oid, bl1, sizeof(buf), 0));
   uint64_t handle;
-  WatchNotifyTestCtx2 ctx(this);
+  WatchNotifyTestCtx2TimeOut ctx(this);
   ASSERT_EQ(0, ioctx.watch3(notify_oid, &handle, &ctx, timeout));
   ASSERT_GT(ioctx.watch_check(handle), 0);
   std::list<obj_watch_t> watches;