diff options
author | Mathias Stearn <mathias@10gen.com> | 2018-11-14 17:28:15 -0500 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2018-11-30 19:21:46 -0500 |
commit | 3cc2238a6e132b1fc67f70a3a137ebf2f4db3849 (patch) | |
tree | b0a839eb988fec6e1e2dcce9cba4a91576c02f30 /src/mongo/util/future_test_future_void.cpp | |
parent | 69e3a7e1b92b72b5332339a9834a239c635f1350 (diff) | |
download | mongo-3cc2238a6e132b1fc67f70a3a137ebf2f4db3849.tar.gz |
SERVER-35682 Add SharedPromise and SharedSemiFuture types
Diffstat (limited to 'src/mongo/util/future_test_future_void.cpp')
-rw-r--r-- | src/mongo/util/future_test_future_void.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/mongo/util/future_test_future_void.cpp b/src/mongo/util/future_test_future_void.cpp index 4095706739f..17585dc4257 100644 --- a/src/mongo/util/future_test_future_void.cpp +++ b/src/mongo/util/future_test_future_void.cpp @@ -68,6 +68,16 @@ TEST(Future_Void, Success_getNothrowRvalue) { [] {}, [](Future<void>&& fut) { ASSERT_EQ(std::move(fut).getNoThrow(), Status::OK()); }); } +TEST(Future_Void, Success_shared_get) { + FUTURE_SUCCESS_TEST([] {}, [](Future<void>&& fut) { std::move(fut).share().get(); }); +} + +TEST(Future_Void, Success_shared_getNothrow) { + FUTURE_SUCCESS_TEST( + [] {}, + [](Future<void>&& fut) { ASSERT_EQ(std::move(fut).share().getNoThrow(), Status::OK()); }); +} + TEST(Future_Void, Success_getAsync) { FUTURE_SUCCESS_TEST( [] {}, @@ -108,6 +118,16 @@ TEST(Future_Void, Fail_getNothrowRvalue) { [](Future<void>&& fut) { ASSERT_EQ(std::move(fut).getNoThrow(), failStatus()); }); } +TEST(Future_Void, Fail_share_getRvalue) { + FUTURE_FAIL_TEST<void>( + [](Future<void>&& fut) { ASSERT_THROWS_failStatus(std::move(fut).share().get()); }); +} + +TEST(Future_Void, Fail_share_getNothrow) { + FUTURE_FAIL_TEST<void>( + [](Future<void>&& fut) { ASSERT_EQ(std::move(fut).share().getNoThrow(), failStatus()); }); +} + TEST(Future_Void, Fail_getAsync) { FUTURE_FAIL_TEST<void>([](Future<void>&& fut) { auto pf = makePromiseFuture<void>(); @@ -149,9 +169,21 @@ TEST(Future_Void, Fail_isReady) { TEST(Future_Void, isReady_TSAN_OK) { bool done = false; auto fut = async([&] { done = true; }); + //(void)*const_cast<volatile bool*>(&done); // Data Race! Uncomment to make sure TSAN works. + while (!fut.isReady()) { + } + ASSERT(done); + fut.get(); + ASSERT(done); +} + +TEST(Future_Void, isReady_share_TSAN_OK) { + bool done = false; + auto fut = async([&] { done = true; }).share(); + //(void)*const_cast<volatile bool*>(&done); // Data Race! Uncomment to make sure TSAN works. while (!fut.isReady()) { } - // ASSERT(done); // Data Race! Uncomment to make sure TSAN is working. + ASSERT(done); fut.get(); ASSERT(done); } |