diff options
author | lexeyo <lexeyo@yandex-team.ru> | 2022-02-10 16:50:52 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:52 +0300 |
commit | c0a1bd5a47467ef8bf618172a331c90a2e70d71f (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/threading/future/subscription/wait_any_ut.cpp | |
parent | 7bd28c29ae2a1fba7a03bcf4c658af66fe1373bf (diff) | |
download | ydb-c0a1bd5a47467ef8bf618172a331c90a2e70d71f.tar.gz |
Restoring authorship annotation for <lexeyo@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/threading/future/subscription/wait_any_ut.cpp')
-rw-r--r-- | library/cpp/threading/future/subscription/wait_any_ut.cpp | 322 |
1 files changed, 161 insertions, 161 deletions
diff --git a/library/cpp/threading/future/subscription/wait_any_ut.cpp b/library/cpp/threading/future/subscription/wait_any_ut.cpp index 91dd7b28cb..262080e8d1 100644 --- a/library/cpp/threading/future/subscription/wait_any_ut.cpp +++ b/library/cpp/threading/future/subscription/wait_any_ut.cpp @@ -1,166 +1,166 @@ -#include "wait_any.h" -#include "wait_ut_common.h" - +#include "wait_any.h" +#include "wait_ut_common.h" + #include <library/cpp/testing/unittest/registar.h> -#include <util/generic/strbuf.h> - -#include <exception> - -using namespace NThreading; - -Y_UNIT_TEST_SUITE(TWaitAnyTest) { - - Y_UNIT_TEST(TestTwoUnsignaled) { - auto p1 = NewPromise<int>(); - auto p2 = NewPromise<int>(); - auto w = NWait::WaitAny(p1.GetFuture(), p2.GetFuture()); - UNIT_ASSERT(!w.HasValue() && !w.HasException()); - - p1.SetValue(10); - UNIT_ASSERT(w.HasValue()); - p2.SetValue(1); - } - - Y_UNIT_TEST(TestTwoUnsignaledWithException) { - auto p1 = NewPromise<int>(); - auto p2 = NewPromise<int>(); - auto w = NWait::WaitAny(p1.GetFuture(), p2.GetFuture()); - UNIT_ASSERT(!w.HasValue() && !w.HasException()); - +#include <util/generic/strbuf.h> + +#include <exception> + +using namespace NThreading; + +Y_UNIT_TEST_SUITE(TWaitAnyTest) { + + Y_UNIT_TEST(TestTwoUnsignaled) { + auto p1 = NewPromise<int>(); + auto p2 = NewPromise<int>(); + auto w = NWait::WaitAny(p1.GetFuture(), p2.GetFuture()); + UNIT_ASSERT(!w.HasValue() && !w.HasException()); + + p1.SetValue(10); + UNIT_ASSERT(w.HasValue()); + p2.SetValue(1); + } + + Y_UNIT_TEST(TestTwoUnsignaledWithException) { + auto p1 = NewPromise<int>(); + auto p2 = NewPromise<int>(); + auto w = NWait::WaitAny(p1.GetFuture(), p2.GetFuture()); + UNIT_ASSERT(!w.HasValue() && !w.HasException()); + constexpr TStringBuf message = "Test exception"; - p2.SetException(std::make_exception_ptr(yexception() << message)); - UNIT_ASSERT_EXCEPTION_SATISFIES(w.TryRethrow(), yexception, [message](auto const& e) { - return message == e.what(); - }); - - p1.SetValue(-11); - } - - Y_UNIT_TEST(TestOneUnsignaledOneSignaled) { - auto p = NewPromise(); - auto f = MakeFuture(); - auto w = NWait::WaitAny(p.GetFuture(), f); - UNIT_ASSERT(w.HasValue()); - - p.SetValue(); - } - - Y_UNIT_TEST(TestOneUnsignaledOneSignaledWithException) { - auto p = NewPromise(); + p2.SetException(std::make_exception_ptr(yexception() << message)); + UNIT_ASSERT_EXCEPTION_SATISFIES(w.TryRethrow(), yexception, [message](auto const& e) { + return message == e.what(); + }); + + p1.SetValue(-11); + } + + Y_UNIT_TEST(TestOneUnsignaledOneSignaled) { + auto p = NewPromise(); + auto f = MakeFuture(); + auto w = NWait::WaitAny(p.GetFuture(), f); + UNIT_ASSERT(w.HasValue()); + + p.SetValue(); + } + + Y_UNIT_TEST(TestOneUnsignaledOneSignaledWithException) { + auto p = NewPromise(); constexpr TStringBuf message = "Test exception 2"; - auto f = MakeErrorFuture<void>(std::make_exception_ptr(yexception() << message)); - auto w = NWait::WaitAny(f, p.GetFuture()); - UNIT_ASSERT_EXCEPTION_SATISFIES(w.TryRethrow(), yexception, [message](auto const& e) { - return message == e.what(); - }); - - p.SetValue(); - } - - Y_UNIT_TEST(TestEmptyInitializer) { - auto w = NWait::WaitAny(std::initializer_list<TFuture<void> const>({})); - UNIT_ASSERT(w.HasValue()); - } - - Y_UNIT_TEST(TestEmptyVector) { - auto w = NWait::WaitAny(TVector<TFuture<int>>()); - UNIT_ASSERT(w.HasValue()); - } - - Y_UNIT_TEST(TestOneUnsignaledWithInitializer) { - auto p = NewPromise<int>(); - auto w = NWait::WaitAny({ p.GetFuture() }); - UNIT_ASSERT(!w.HasValue() && !w.HasException()); - - p.SetValue(1); - UNIT_ASSERT(w.HasValue()); - } - - Y_UNIT_TEST(TestOneUnsignaledWithVector) { - auto p = NewPromise(); - auto w = NWait::WaitAny(TVector<TFuture<void>>{ p.GetFuture() }); - UNIT_ASSERT(!w.HasValue() && !w.HasException()); - + auto f = MakeErrorFuture<void>(std::make_exception_ptr(yexception() << message)); + auto w = NWait::WaitAny(f, p.GetFuture()); + UNIT_ASSERT_EXCEPTION_SATISFIES(w.TryRethrow(), yexception, [message](auto const& e) { + return message == e.what(); + }); + + p.SetValue(); + } + + Y_UNIT_TEST(TestEmptyInitializer) { + auto w = NWait::WaitAny(std::initializer_list<TFuture<void> const>({})); + UNIT_ASSERT(w.HasValue()); + } + + Y_UNIT_TEST(TestEmptyVector) { + auto w = NWait::WaitAny(TVector<TFuture<int>>()); + UNIT_ASSERT(w.HasValue()); + } + + Y_UNIT_TEST(TestOneUnsignaledWithInitializer) { + auto p = NewPromise<int>(); + auto w = NWait::WaitAny({ p.GetFuture() }); + UNIT_ASSERT(!w.HasValue() && !w.HasException()); + + p.SetValue(1); + UNIT_ASSERT(w.HasValue()); + } + + Y_UNIT_TEST(TestOneUnsignaledWithVector) { + auto p = NewPromise(); + auto w = NWait::WaitAny(TVector<TFuture<void>>{ p.GetFuture() }); + UNIT_ASSERT(!w.HasValue() && !w.HasException()); + constexpr TStringBuf message = "Test exception 3"; - p.SetException(std::make_exception_ptr(yexception() << message)); - UNIT_ASSERT_EXCEPTION_SATISFIES(w.TryRethrow(), yexception, [message](auto const& e) { - return message == e.what(); - }); - } - - Y_UNIT_TEST(TestManyUnsignaledWithInitializer) { - auto p1 = NewPromise<int>(); - auto p2 = NewPromise<int>(); - auto p3 = NewPromise<int>(); - auto w = NWait::WaitAny({ p1.GetFuture(), p2.GetFuture(), p3.GetFuture() }); - UNIT_ASSERT(!w.HasValue() && !w.HasException()); - - p1.SetValue(42); - UNIT_ASSERT(w.HasValue()); - - p2.SetValue(-3); - p3.SetValue(12); - } - - Y_UNIT_TEST(TestManyMixedWithInitializer) { - auto p1 = NewPromise<int>(); - auto p2 = NewPromise<int>(); - auto f = MakeFuture(42); - auto w = NWait::WaitAny({ p1.GetFuture(), f, p2.GetFuture() }); - UNIT_ASSERT(w.HasValue()); - - p1.SetValue(10); - p2.SetValue(-3); - } - - - Y_UNIT_TEST(TestManyUnsignaledWithVector) { - auto p1 = NewPromise(); - auto p2 = NewPromise(); - auto p3 = NewPromise(); - auto w = NWait::WaitAny(TVector<TFuture<void>>{ p1.GetFuture(), p2.GetFuture(), p3.GetFuture() }); - UNIT_ASSERT(!w.HasValue() && !w.HasException()); - + p.SetException(std::make_exception_ptr(yexception() << message)); + UNIT_ASSERT_EXCEPTION_SATISFIES(w.TryRethrow(), yexception, [message](auto const& e) { + return message == e.what(); + }); + } + + Y_UNIT_TEST(TestManyUnsignaledWithInitializer) { + auto p1 = NewPromise<int>(); + auto p2 = NewPromise<int>(); + auto p3 = NewPromise<int>(); + auto w = NWait::WaitAny({ p1.GetFuture(), p2.GetFuture(), p3.GetFuture() }); + UNIT_ASSERT(!w.HasValue() && !w.HasException()); + + p1.SetValue(42); + UNIT_ASSERT(w.HasValue()); + + p2.SetValue(-3); + p3.SetValue(12); + } + + Y_UNIT_TEST(TestManyMixedWithInitializer) { + auto p1 = NewPromise<int>(); + auto p2 = NewPromise<int>(); + auto f = MakeFuture(42); + auto w = NWait::WaitAny({ p1.GetFuture(), f, p2.GetFuture() }); + UNIT_ASSERT(w.HasValue()); + + p1.SetValue(10); + p2.SetValue(-3); + } + + + Y_UNIT_TEST(TestManyUnsignaledWithVector) { + auto p1 = NewPromise(); + auto p2 = NewPromise(); + auto p3 = NewPromise(); + auto w = NWait::WaitAny(TVector<TFuture<void>>{ p1.GetFuture(), p2.GetFuture(), p3.GetFuture() }); + UNIT_ASSERT(!w.HasValue() && !w.HasException()); + constexpr TStringBuf message = "Test exception 4"; - p2.SetException(std::make_exception_ptr(yexception() << message)); - UNIT_ASSERT_EXCEPTION_SATISFIES(w.TryRethrow(), yexception, [message](auto const& e) { - return message == e.what(); - }); - - p1.SetValue(); - p3.SetValue(); - } - - - Y_UNIT_TEST(TestManyMixedWithVector) { - auto p1 = NewPromise(); - auto p2 = NewPromise(); - auto f = MakeFuture(); - auto w = NWait::WaitAny(TVector<TFuture<void>>{ p1.GetFuture(), p2.GetFuture(), f }); - UNIT_ASSERT(w.HasValue()); - - p1.SetValue(); - p2.SetValue(); - } - - Y_UNIT_TEST(TestManyStress) { - NTest::TestManyStress<void>([](auto&& futures) { return NWait::WaitAny(futures); } - , [](size_t) { - return [](auto&& p) { p.SetValue(); }; - } - , [](auto&& waiter) { UNIT_ASSERT(waiter.HasValue()); }); - - NTest::TestManyStress<int>([](auto&& futures) { return NWait::WaitAny(futures); } - , [](size_t) { - return [](auto&& p) { p.SetValue(22); }; - } - , [](auto&& waiter) { UNIT_ASSERT(waiter.HasValue()); }); - auto e = std::make_exception_ptr(yexception() << "Test exception 5"); - NTest::TestManyStress<void>([](auto&& futures) { return NWait::WaitAny(futures); } - , [e](size_t) { - return [e](auto&& p) { p.SetException(e); }; - } - , [](auto&& waiter) { UNIT_ASSERT(waiter.HasException()); }); - } - -} + p2.SetException(std::make_exception_ptr(yexception() << message)); + UNIT_ASSERT_EXCEPTION_SATISFIES(w.TryRethrow(), yexception, [message](auto const& e) { + return message == e.what(); + }); + + p1.SetValue(); + p3.SetValue(); + } + + + Y_UNIT_TEST(TestManyMixedWithVector) { + auto p1 = NewPromise(); + auto p2 = NewPromise(); + auto f = MakeFuture(); + auto w = NWait::WaitAny(TVector<TFuture<void>>{ p1.GetFuture(), p2.GetFuture(), f }); + UNIT_ASSERT(w.HasValue()); + + p1.SetValue(); + p2.SetValue(); + } + + Y_UNIT_TEST(TestManyStress) { + NTest::TestManyStress<void>([](auto&& futures) { return NWait::WaitAny(futures); } + , [](size_t) { + return [](auto&& p) { p.SetValue(); }; + } + , [](auto&& waiter) { UNIT_ASSERT(waiter.HasValue()); }); + + NTest::TestManyStress<int>([](auto&& futures) { return NWait::WaitAny(futures); } + , [](size_t) { + return [](auto&& p) { p.SetValue(22); }; + } + , [](auto&& waiter) { UNIT_ASSERT(waiter.HasValue()); }); + auto e = std::make_exception_ptr(yexception() << "Test exception 5"); + NTest::TestManyStress<void>([](auto&& futures) { return NWait::WaitAny(futures); } + , [e](size_t) { + return [e](auto&& p) { p.SetException(e); }; + } + , [](auto&& waiter) { UNIT_ASSERT(waiter.HasException()); }); + } + +} |