From: Samuel Just Date: Thu, 16 Mar 2023 20:22:22 +0000 (+0000) Subject: test/crimson/test_errorator: move tests into TEST_F declarations X-Git-Tag: v19.1.1~386^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f99e36b1ff7b4aa851bc296d04ecc110a1ad2264;p=ceph.git test/crimson/test_errorator: move tests into TEST_F declarations Slightly easier to read this way. Signed-off-by: Samuel Just (cherry picked from commit 3f377f013c690d9c17685967f1ebc4dc2adbf838) --- diff --git a/src/test/crimson/test_errorator.cc b/src/test/crimson/test_errorator.cc index 939c6cde81ae..4eccb1a9dcb7 100644 --- a/src/test/crimson/test_errorator.cc +++ b/src/test/crimson/test_errorator.cc @@ -13,33 +13,7 @@ struct errorator_test_t : public seastar_test_suite_t { using ertr = crimson::errorator; - ertr::future<> test_do_until() { - return crimson::repeat([i=0]() mutable { - if (i < 5) { - ++i; - return ertr::make_ready_future( - seastar::stop_iteration::no); - } else { - return ertr::make_ready_future( - seastar::stop_iteration::yes); - } - }); - } - static constexpr int SIZE = 42; - ertr::future<> test_parallel_for_each() { - auto sum = std::make_unique(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 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). - return ertr::now().safe_then([] { - return 42; - }).safe_then([](int life) { - return ertr::make_ready_future(life); - }); - } -private: - ertr::future create_noncopyable() { - return ertr::make_ready_future(); - } }; 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::no); + } else { + return ertr::make_ready_future( + 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(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(); + }; + 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). + return ertr::now().safe_then([] { + return 42; + }).safe_then([](int life) { + return ertr::make_ready_future(life); + }).unsafe_get0(); }); }