]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/seastar/tests/unit/closeable_test.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / seastar / tests / unit / closeable_test.cc
index 0eb179a7dca81241f7c9a8f0cd6e2a060fb6213e..ef81f5938c30b231e749aecf6bab51758588a9b6 100644 (file)
@@ -56,6 +56,22 @@ SEASTAR_TEST_CASE(deferred_close_test) {
   });
 }
 
+SEASTAR_TEST_CASE(move_deferred_close_test) {
+  return do_with(gate(), [] (gate& g) {
+    return async([&] {
+        auto close_gate = make_shared(deferred_close(g));
+        // g.close() should not be called when deferred_close is moved away
+        BOOST_REQUIRE(!g.is_closed());
+    }).then([&] {
+        // Before this test is exercised, gate::close() would run into a
+        // assert failure when leaving previous continuation, if gate::close()
+        // is called twice, so this test only verifies the behavior with the
+        // release build.
+        BOOST_REQUIRE(g.is_closed());
+    });
+  });
+}
+
 SEASTAR_TEST_CASE(close_now_test) {
   return do_with(gate(), 0, 42, [] (gate& g, int& count, int& expected) {
     return async([&] {
@@ -75,6 +91,16 @@ SEASTAR_TEST_CASE(close_now_test) {
   });
 }
 
+SEASTAR_TEST_CASE(cancel_deferred_close_test) {
+    gate g;
+    {
+        auto close_gate = deferred_close(g);
+        close_gate.cancel();
+    }
+    g.check(); // should not throw
+    return make_ready_future<>();
+}
+
 SEASTAR_TEST_CASE(with_closeable_test) {
     return do_with(0, 42, [] (int& count, int& expected) {
         return with_closeable(gate(), [&] (gate& g) {
@@ -145,6 +171,16 @@ public:
 
 } // anonymous namespace
 
+SEASTAR_TEST_CASE(cancel_deferred_stop_test) {
+    count_stops cs;
+    {
+        auto stop = deferred_stop(cs);
+        stop.cancel();
+    }
+    BOOST_REQUIRE_EQUAL(cs.stopped(), 0);
+    return make_ready_future<>();
+}
+
 SEASTAR_TEST_CASE(deferred_stop_test) {
   return do_with(count_stops(), [] (count_stops& cs) {
     return async([&] {
@@ -156,6 +192,18 @@ SEASTAR_TEST_CASE(deferred_stop_test) {
   });
 }
 
+SEASTAR_TEST_CASE(move_deferred_stop_test) {
+  return do_with(count_stops(), [] (count_stops& cs) {
+    return async([&] {
+        auto stop = make_shared(deferred_stop(cs));
+    }).then([&] {
+        // cs.stop() should be called once and only once
+        // when stop is destroyed
+        BOOST_REQUIRE_EQUAL(cs.stopped(), 1);
+    });
+  });
+}
+
 SEASTAR_TEST_CASE(stop_now_test) {
   return do_with(count_stops(), [] (count_stops& cs) {
     return async([&] {
@@ -198,6 +246,45 @@ SEASTAR_TEST_CASE(with_stoppable_exception_test) {
     });
 }
 
+SEASTAR_THREAD_TEST_CASE(move_open_gate_test) {
+    gate g1;
+    g1.enter();
+    // move an open gate
+    gate g2 = std::move(g1);
+    // the state in g1 should be moved into g2
+    BOOST_CHECK_EQUAL(g1.get_count(), 0);
+    BOOST_REQUIRE_EQUAL(g2.get_count(), 1);
+    g2.leave();
+    g2.close().get();
+    BOOST_CHECK(!g1.is_closed());
+    BOOST_CHECK(g2.is_closed());
+}
+
+SEASTAR_THREAD_TEST_CASE(move_closing_gate_test) {
+    gate g1;
+    g1.enter();
+    auto fut = g1.close();
+    // move a closing gate
+    gate g2 = std::move(g1);
+    BOOST_CHECK_EQUAL(g1.get_count(), 0);
+    BOOST_REQUIRE_EQUAL(g2.get_count(), 1);
+    g2.leave();
+    fut.get();
+    BOOST_CHECK(!g1.is_closed());
+    BOOST_CHECK(g2.is_closed());
+}
+
+SEASTAR_THREAD_TEST_CASE(move_closed_gate_test) {
+    gate g1;
+    g1.close().get();
+    // move a closed gate
+    gate g2 = std::move(g1);
+    BOOST_CHECK_EQUAL(g1.get_count(), 0);
+    BOOST_CHECK_EQUAL(g2.get_count(), 0);
+    BOOST_CHECK(!g1.is_closed());
+    BOOST_CHECK(g2.is_closed());
+}
+
 SEASTAR_THREAD_TEST_CASE(gate_holder_basic_test) {
     gate g;
     auto gh = g.hold();