]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/crimson: verify the futurization in an errorated future. 41457/head
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Thu, 20 May 2021 19:18:21 +0000 (19:18 +0000)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Thu, 20 May 2021 19:28:14 +0000 (19:28 +0000)
`seastar::future` allows a lambda passed to e.g. `then()` to
return not only a future but also any non-future type like
a plain integer:

  ```cpp
  seastar::now().then([] {
    return 42;
  }).then([] (int futurized_life) {
    // ...
  });
  ```

In such case, the plain type is being wrapped in a future.
This process is called _futurization_ and is performed by
`seastar::futurize` called from the internals of `future`.

In this commit we want to ensure analogous facility is offered
by errorated futures.

Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/test/crimson/test_errorator.cc

index 57dbc78cf9993e0414c21ac72e16284111afa58e..ad1223295a16d5e11fd9f22675e30792ef2b7c87 100644 (file)
@@ -31,6 +31,17 @@ struct errorator_test_t : public seastar_test_suite_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>();
@@ -50,3 +61,10 @@ TEST_F(errorator_test_t, non_copy_then)
     test_non_copy_then().unsafe_get0();
   });
 }
+
+TEST_F(errorator_test_t, test_futurization)
+{
+  run_async([this] {
+    test_futurization().unsafe_get0();
+  });
+}