]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/crimson/test_interruptible_future: add UT cases for interruption 67740/head
authorXuehan Xu <xuxuehan@qianxin.com>
Wed, 11 Mar 2026 08:04:51 +0000 (16:04 +0800)
committerXuehan Xu <xuxuehan@qianxin.com>
Wed, 11 Mar 2026 09:37:34 +0000 (17:37 +0800)
handling in interruptor::green_get/yield/maybe_yield

Signed-off-by: Xuehan Xu <xuxuehan@qianxin.com>
src/test/crimson/test_interruptible_future.cc

index 697c35788729ca1e3bdaeb13acba9bc0bf8e1d43..338a82e8e29d3e3d84b8edd48eb146f38b7fe14a 100644 (file)
@@ -35,6 +35,10 @@ public:
       return true;
     return false;
   }
+
+  void set_interrupt() {
+    interrupt = true;
+  }
 private:
   bool interrupt = false;
 };
@@ -262,6 +266,66 @@ TEST_F(seastar_test_suite_t, interruptible_async)
       return fut;
     }, [](std::exception_ptr) {}, false).get();
   });
+
+}
+
+TEST_F(seastar_test_suite_t, interruptible_yield)
+{
+  using interruptor =
+    interruptible::interruptor<TestInterruptCondition>;
+
+  run_async([] {
+    bool interrupted = false;
+    auto fut = interruptor::with_interruption([] {
+      return interruptor::async([] {
+        interruptible::interrupt_cond<
+         TestInterruptCondition>.interrupt_cond->set_interrupt();
+        interruptor::yield();
+        // the execution should be interrupted, the run should
+        // never reach here.
+        ceph_abort();
+      });
+    }, [&interrupted](std::exception_ptr) {
+      std::cout << "interrupted" << std::endl;
+      interrupted = true;
+    }, false);
+    fut.wait();
+    ceph_assert(interrupted);
+
+    interrupted = false;
+    fut = interruptor::with_interruption([] {
+      return interruptor::async([] {
+        interruptible::interrupt_cond<
+         TestInterruptCondition>.interrupt_cond->set_interrupt();
+        interruptor::green_get(seastar::yield());
+        // the execution should be interrupted, the run should
+        // never reach here.
+        ceph_abort();
+      });
+    }, [&interrupted](std::exception_ptr) {
+      std::cout << "interrupted" << std::endl;
+      interrupted = true;
+    }, false);
+    fut.wait();
+    ceph_assert(interrupted);
+
+    interrupted = false;
+    fut = interruptor::with_interruption([] {
+      return interruptor::async([] {
+        interruptible::interrupt_cond<
+         TestInterruptCondition>.interrupt_cond->set_interrupt();
+        interruptor::make_interruptible(seastar::yield()).get();
+        // the execution should be interrupted, the run should
+        // never reach here.
+        ceph_abort();
+      });
+    }, [&interrupted](std::exception_ptr) {
+      std::cout << "interrupted" << std::endl;
+      interrupted = true;
+    }, false);
+    fut.wait();
+    ceph_assert(interrupted);
+  });
 }
 
 TEST_F(seastar_test_suite_t, DISABLED_nested_interruptors)