]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
test/crimson/test_errorator: move tests into TEST_F declarations
authorSamuel Just <sjust@redhat.com>
Thu, 16 Mar 2023 20:22:22 +0000 (20:22 +0000)
committerMatan Breizman <mbreizma@redhat.com>
Wed, 8 May 2024 07:05:36 +0000 (10:05 +0300)
Slightly easier to read this way.

Signed-off-by: Samuel Just <sjust@redhat.com>
(cherry picked from commit 3f377f013c690d9c17685967f1ebc4dc2adbf838)

src/test/crimson/test_errorator.cc

index 939c6cde81ae2f8371cb080e83c4229af2effb5b..4eccb1a9dcb78b5cb92dbc7cc1c71cbcb97815c2 100644 (file)
 
 struct errorator_test_t : public seastar_test_suite_t {
   using ertr = crimson::errorator<crimson::ct_error::invarg>;
-  ertr::future<> test_do_until() {
-    return crimson::repeat([i=0]() mutable {
-      if (i < 5) {
-        ++i;
-        return ertr::make_ready_future<seastar::stop_iteration>(
-          seastar::stop_iteration::no);
-      } else {
-        return ertr::make_ready_future<seastar::stop_iteration>(
-          seastar::stop_iteration::yes);
-      }
-    });
-  }
-  static constexpr int SIZE = 42;
-  ertr::future<> test_parallel_for_each() {
-    auto sum = std::make_unique<int>(0);
-    return ertr::parallel_for_each(
-      boost::make_counting_iterator(0),
-      boost::make_counting_iterator(SIZE),
-      [sum=sum.get()](int i) {
-       *sum += i;
-    }).safe_then([sum=std::move(sum)] {
-      int expected = std::accumulate(boost::make_counting_iterator(0),
-                                    boost::make_counting_iterator(SIZE),
-                                    0);
-      ASSERT_EQ(*sum, expected);
-    });
-  }
+
   struct noncopyable_t {
     constexpr noncopyable_t() = default;
     ~noncopyable_t() = default;
@@ -48,52 +22,66 @@ struct errorator_test_t : public seastar_test_suite_t {
     noncopyable_t(const noncopyable_t&) = delete;
     noncopyable_t& operator=(const noncopyable_t&) = delete;
   };
-  ertr::future<> test_non_copy_then() {
-    return create_noncopyable().safe_then([](auto t) {
-      return ertr::now();
-    });
-  }
-  ertr::future<int> test_futurization() {
-    // we don't want to be enforced to always do `make_ready_future(...)`.
-    // as in seastar::future, the futurization should take care about
-    // turning non-future types (e.g. int) into futurized ones (e.g.
-    // ertr::future<int>).
-    return ertr::now().safe_then([] {
-      return 42;
-    }).safe_then([](int life) {
-      return ertr::make_ready_future<int>(life);
-    });
-  }
-private:
-  ertr::future<noncopyable_t> create_noncopyable() {
-    return ertr::make_ready_future<noncopyable_t>();
-  }
 };
 
 TEST_F(errorator_test_t, basic)
 {
-  run_async([this] {
-    test_do_until().unsafe_get0();
+  run_async([] {
+    return crimson::repeat([i=0]() mutable {
+      if (i < 5) {
+        ++i;
+        return ertr::make_ready_future<seastar::stop_iteration>(
+          seastar::stop_iteration::no);
+      } else {
+        return ertr::make_ready_future<seastar::stop_iteration>(
+          seastar::stop_iteration::yes);
+      }
+    }).unsafe_get0();
   });
 }
 
 TEST_F(errorator_test_t, parallel_for_each)
 {
-  run_async([this] {
-    test_parallel_for_each().unsafe_get0();
+  run_async([] {
+    static constexpr int SIZE = 42;
+    auto sum = std::make_unique<int>(0);
+    return ertr::parallel_for_each(
+      boost::make_counting_iterator(0),
+      boost::make_counting_iterator(SIZE),
+      [sum=sum.get()](int i) {
+       *sum += i;
+      }).safe_then([sum=std::move(sum)] {
+       int expected = std::accumulate(boost::make_counting_iterator(0),
+                                      boost::make_counting_iterator(SIZE),
+                                      0);
+       ASSERT_EQ(*sum, expected);
+      }).unsafe_get0();
   });
 }
 
 TEST_F(errorator_test_t, non_copy_then)
 {
-  run_async([this] {
-    test_non_copy_then().unsafe_get0();
+  run_async([] {
+    auto create_noncopyable = [] {
+      return ertr::make_ready_future<noncopyable_t>();
+    };
+    return create_noncopyable().safe_then([](auto) {
+      return ertr::now();
+    }).unsafe_get0();
   });
 }
 
 TEST_F(errorator_test_t, test_futurization)
 {
-  run_async([this] {
-    test_futurization().unsafe_get0();
+  run_async([] {
+    // we don't want to be enforced to always do `make_ready_future(...)`.
+    // as in seastar::future, the futurization should take care about
+    // turning non-future types (e.g. int) into futurized ones (e.g.
+    // ertr::future<int>).
+    return ertr::now().safe_then([] {
+      return 42;
+    }).safe_then([](int life) {
+      return ertr::make_ready_future<int>(life);
+    }).unsafe_get0();
   });
 }