diff options
author | Ben Caimano <ben.caimano@10gen.com> | 2020-11-17 23:45:12 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-11-23 20:24:09 +0000 |
commit | f226050b2846e9fdbeff14ca606494c24179fb16 (patch) | |
tree | 434989046c8079d72471f36e1181c3652257a361 /src/mongo/util/future_test_promise_void.cpp | |
parent | 829617a5c30b6aa20f36950a165ea35e2c17dc2d (diff) | |
download | mongo-f226050b2846e9fdbeff14ca606494c24179fb16.tar.gz |
SERVER-52939 Expand Promise::setFrom()
Promise<void> can now be set from a Status and Promise<T> now rejects
being implicitly set from a Status or T.
Diffstat (limited to 'src/mongo/util/future_test_promise_void.cpp')
-rw-r--r-- | src/mongo/util/future_test_promise_void.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/mongo/util/future_test_promise_void.cpp b/src/mongo/util/future_test_promise_void.cpp index 3ef9731e7a7..c57f5db1b78 100644 --- a/src/mongo/util/future_test_promise_void.cpp +++ b/src/mongo/util/future_test_promise_void.cpp @@ -40,7 +40,11 @@ namespace mongo { namespace { -TEST(Promise_void, Success_setFrom) { +static_assert(!canSetFrom<Promise<void>, void>, "Use Promise<T>::emplaceValue() instead"); +static_assert(canSetFrom<Promise<void>, Status>); +static_assert(canSetFrom<Promise<void>, Future<void>>); + +TEST(Promise_void, Success_setFrom_future) { FUTURE_SUCCESS_TEST<kNoExecutorFuture_needsPromiseSetFrom>( [] {}, [](/*Future<void>*/ auto&& fut) { @@ -51,7 +55,13 @@ TEST(Promise_void, Success_setFrom) { }); } -TEST(Promise_void, Fail_setFrom) { +TEST(Promise_void, Success_setFrom_status) { + auto pf = makePromiseFuture<void>(); + pf.promise.setFrom(Status::OK()); + ASSERT_OK(std::move(pf.future).getNoThrow()); +} + +TEST(Promise_void, Fail_setFrom_future) { FUTURE_FAIL_TEST<void, kNoExecutorFuture_needsPromiseSetFrom>([](/*Future<void>*/ auto&& fut) { auto pf = makePromiseFuture<void>(); pf.promise.setFrom(std::move(fut)); @@ -59,6 +69,12 @@ TEST(Promise_void, Fail_setFrom) { }); } +TEST(Promise_void, Fail_setFrom_status) { + auto pf = makePromiseFuture<void>(); + pf.promise.setFrom(failStatus()); + ASSERT_THROWS_failStatus(std::move(pf.future).get()); +} + TEST(Promise_void, Success_setWith_value) { auto pf = makePromiseFuture<void>(); pf.promise.setWith([&] {}); |