]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/crimson: add test case for errorator parallel_for_each 41848/head
authorXuehan Xu <xxhdx1985126@gmail.com>
Thu, 10 Jun 2021 06:21:01 +0000 (14:21 +0800)
committerXuehan Xu <xxhdx1985126@gmail.com>
Wed, 16 Jun 2021 09:04:10 +0000 (17:04 +0800)
Signed-off-by: Xuehan Xu <xxhdx1985126@gmail.com>
src/test/crimson/test_errorator.cc

index ad1223295a16d5e11fd9f22675e30792ef2b7c87..8e4f09795fc818e3588a5d86dc991e64e430fc95 100644 (file)
@@ -1,10 +1,14 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*-
 // vim: ts=8 sw=2 smarttab
 
+#include <boost/iterator/counting_iterator.hpp>
+#include <numeric>
+
 #include "test/crimson/gtest_seastar.h"
 
 #include "crimson/common/errorator.h"
 #include "crimson/common/log.h"
+#include "seastar/core/sleep.hh"
 
 struct errorator_test_t : public seastar_test_suite_t {
   using ertr = crimson::errorator<crimson::ct_error::invarg>;
@@ -18,6 +22,21 @@ struct errorator_test_t : public seastar_test_suite_t {
       }
     });
   }
+  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;
@@ -55,6 +74,13 @@ TEST_F(errorator_test_t, basic)
   });
 }
 
+TEST_F(errorator_test_t, parallel_for_each)
+{
+  run_async([this] {
+    test_parallel_for_each().unsafe_get0();
+  });
+}
+
 TEST_F(errorator_test_t, non_copy_then)
 {
   run_async([this] {