]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/crimson/test_errorator.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / test / crimson / test_errorator.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "test/crimson/gtest_seastar.h"
5
6 #include "crimson/common/errorator.h"
7 #include "crimson/common/log.h"
8
9 struct errorator_test_t : public seastar_test_suite_t {
10 using ertr = crimson::errorator<crimson::ct_error::invarg>;
11 ertr::future<> test_do_until() {
12 return crimson::do_until([i=0]() mutable {
13 if (i < 5) {
14 ++i;
15 return ertr::make_ready_future<bool>(false);
16 } else {
17 return ertr::make_ready_future<bool>(true);
18 }
19 });
20 }
21 struct noncopyable_t {
22 constexpr noncopyable_t() = default;
23 ~noncopyable_t() = default;
24 noncopyable_t(noncopyable_t&&) = default;
25 private:
26 noncopyable_t(const noncopyable_t&) = delete;
27 noncopyable_t& operator=(const noncopyable_t&) = delete;
28 };
29 ertr::future<> test_non_copy_then() {
30 return create_noncopyable().safe_then([](auto t) {
31 return ertr::now();
32 });
33 }
34 private:
35 ertr::future<noncopyable_t> create_noncopyable() {
36 return ertr::make_ready_future<noncopyable_t>();
37 }
38 };
39
40 TEST_F(errorator_test_t, basic)
41 {
42 run_async([this] {
43 test_do_until().unsafe_get0();
44 });
45 }
46
47 TEST_F(errorator_test_t, non_copy_then)
48 {
49 run_async([this] {
50 test_non_copy_then().unsafe_get0();
51 });
52 }