diff options
author | amatanhead <amatanhead@yandex-team.ru> | 2022-02-10 16:50:04 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:04 +0300 |
commit | 8879605a63ac17539be5b3bd41b529791f4d4b02 (patch) | |
tree | 5739c7303cbe09d02b881e25bb294a4a173422a0 /library/cpp/actors/core/ask_ut.cpp | |
parent | 830fe7ae4073c2707f3f3138303ccc56052c0327 (diff) | |
download | ydb-8879605a63ac17539be5b3bd41b529791f4d4b02.tar.gz |
Restoring authorship annotation for <amatanhead@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/actors/core/ask_ut.cpp')
-rw-r--r-- | library/cpp/actors/core/ask_ut.cpp | 248 |
1 files changed, 124 insertions, 124 deletions
diff --git a/library/cpp/actors/core/ask_ut.cpp b/library/cpp/actors/core/ask_ut.cpp index e72ebdba9b..4b53520cee 100644 --- a/library/cpp/actors/core/ask_ut.cpp +++ b/library/cpp/actors/core/ask_ut.cpp @@ -1,131 +1,131 @@ #include <library/cpp/testing/unittest/registar.h> - -#include "actorsystem.h" - -#include <library/cpp/actors/testlib/test_runtime.h> - -using namespace NActors; - -class TPingPong: public TActor<TPingPong> { -public: - TPingPong() - : TActor(&TPingPong::Main) - { - } - - STATEFN(Main) { - switch (ev->GetTypeRewrite()) { - hFunc(TEvents::TEvPing, OnPing); - hFunc(TEvents::TEvBlob, OnBlob); - } - } - - void OnPing(const TEvents::TEvPing::TPtr& ev) { - Send(ev->Sender, new TEvents::TEvPong); - } - - void OnBlob(const TEvents::TEvBlob::TPtr& ev) { - Send(ev->Sender, ev->Release().Release()); - } -}; - -class TPing: public TActor<TPing> { -public: - TPing() - : TActor(&TPing::Main) - { - } - - STATEFN(Main) { - Y_UNUSED(ev); - } -}; - -THolder<TTestActorRuntimeBase> CreateRuntime() { - auto runtime = MakeHolder<TTestActorRuntimeBase>(); - runtime->SetScheduledEventFilter([](auto&&, auto&&, auto&&, auto&&) { return false; }); - runtime->Initialize(); - return runtime; -} - -Y_UNIT_TEST_SUITE(AskActor) { - Y_UNIT_TEST(Ok) { - auto runtime = CreateRuntime(); - auto pingpong = runtime->Register(new TPingPong); - - { - auto fut = runtime->GetAnyNodeActorSystem()->Ask<TEvents::TEvPong>( - pingpong, + +#include "actorsystem.h" + +#include <library/cpp/actors/testlib/test_runtime.h> + +using namespace NActors; + +class TPingPong: public TActor<TPingPong> { +public: + TPingPong() + : TActor(&TPingPong::Main) + { + } + + STATEFN(Main) { + switch (ev->GetTypeRewrite()) { + hFunc(TEvents::TEvPing, OnPing); + hFunc(TEvents::TEvBlob, OnBlob); + } + } + + void OnPing(const TEvents::TEvPing::TPtr& ev) { + Send(ev->Sender, new TEvents::TEvPong); + } + + void OnBlob(const TEvents::TEvBlob::TPtr& ev) { + Send(ev->Sender, ev->Release().Release()); + } +}; + +class TPing: public TActor<TPing> { +public: + TPing() + : TActor(&TPing::Main) + { + } + + STATEFN(Main) { + Y_UNUSED(ev); + } +}; + +THolder<TTestActorRuntimeBase> CreateRuntime() { + auto runtime = MakeHolder<TTestActorRuntimeBase>(); + runtime->SetScheduledEventFilter([](auto&&, auto&&, auto&&, auto&&) { return false; }); + runtime->Initialize(); + return runtime; +} + +Y_UNIT_TEST_SUITE(AskActor) { + Y_UNIT_TEST(Ok) { + auto runtime = CreateRuntime(); + auto pingpong = runtime->Register(new TPingPong); + + { + auto fut = runtime->GetAnyNodeActorSystem()->Ask<TEvents::TEvPong>( + pingpong, THolder(new TEvents::TEvPing)); - runtime->DispatchEvents(); - fut.ExtractValueSync(); - } - - { - auto fut = runtime->GetAnyNodeActorSystem()->Ask<TEvents::TEvBlob>( - pingpong, + runtime->DispatchEvents(); + fut.ExtractValueSync(); + } + + { + auto fut = runtime->GetAnyNodeActorSystem()->Ask<TEvents::TEvBlob>( + pingpong, THolder(new TEvents::TEvBlob("hello!"))); - runtime->DispatchEvents(); - auto ev = fut.ExtractValueSync(); - UNIT_ASSERT_VALUES_EQUAL(ev->Blob, "hello!"); - } - - { - auto fut = runtime->GetAnyNodeActorSystem()->Ask<IEventBase>( - pingpong, + runtime->DispatchEvents(); + auto ev = fut.ExtractValueSync(); + UNIT_ASSERT_VALUES_EQUAL(ev->Blob, "hello!"); + } + + { + auto fut = runtime->GetAnyNodeActorSystem()->Ask<IEventBase>( + pingpong, THolder(new TEvents::TEvPing)); - runtime->DispatchEvents(); - auto ev = fut.ExtractValueSync(); - UNIT_ASSERT_VALUES_EQUAL(ev->Type(), TEvents::TEvPong::EventType); - } - } - - Y_UNIT_TEST(Err) { - auto runtime = CreateRuntime(); - auto pingpong = runtime->Register(new TPingPong); - - { - auto fut = runtime->GetAnyNodeActorSystem()->Ask<TEvents::TEvBlob>( - pingpong, + runtime->DispatchEvents(); + auto ev = fut.ExtractValueSync(); + UNIT_ASSERT_VALUES_EQUAL(ev->Type(), TEvents::TEvPong::EventType); + } + } + + Y_UNIT_TEST(Err) { + auto runtime = CreateRuntime(); + auto pingpong = runtime->Register(new TPingPong); + + { + auto fut = runtime->GetAnyNodeActorSystem()->Ask<TEvents::TEvBlob>( + pingpong, THolder(new TEvents::TEvPing)); - runtime->DispatchEvents(); - UNIT_ASSERT_EXCEPTION_CONTAINS( - fut.ExtractValueSync(), - yexception, - "received unexpected response HelloWorld: Pong"); - } - } - - Y_UNIT_TEST(Timeout) { - auto runtime = CreateRuntime(); - auto ping = runtime->Register(new TPing); - - { - auto fut = runtime->GetAnyNodeActorSystem()->Ask<TEvents::TEvPong>( - ping, + runtime->DispatchEvents(); + UNIT_ASSERT_EXCEPTION_CONTAINS( + fut.ExtractValueSync(), + yexception, + "received unexpected response HelloWorld: Pong"); + } + } + + Y_UNIT_TEST(Timeout) { + auto runtime = CreateRuntime(); + auto ping = runtime->Register(new TPing); + + { + auto fut = runtime->GetAnyNodeActorSystem()->Ask<TEvents::TEvPong>( + ping, THolder(new TEvents::TEvPing), - TDuration::Seconds(1)); - auto start = runtime->GetCurrentTime(); - runtime->DispatchEvents({}, TDuration::Seconds(5)); - UNIT_ASSERT_EXCEPTION_CONTAINS( - fut.ExtractValueSync(), - yexception, - "ask timeout"); - UNIT_ASSERT_VALUES_EQUAL(runtime->GetCurrentTime() - start, TDuration::Seconds(1)); - } - - { - auto fut = runtime->GetAnyNodeActorSystem()->Ask<IEventBase>( - ping, + TDuration::Seconds(1)); + auto start = runtime->GetCurrentTime(); + runtime->DispatchEvents({}, TDuration::Seconds(5)); + UNIT_ASSERT_EXCEPTION_CONTAINS( + fut.ExtractValueSync(), + yexception, + "ask timeout"); + UNIT_ASSERT_VALUES_EQUAL(runtime->GetCurrentTime() - start, TDuration::Seconds(1)); + } + + { + auto fut = runtime->GetAnyNodeActorSystem()->Ask<IEventBase>( + ping, THolder(new TEvents::TEvPing), - TDuration::Seconds(1)); - auto start = runtime->GetCurrentTime(); - runtime->DispatchEvents({}, TDuration::Seconds(5)); - UNIT_ASSERT_EXCEPTION_CONTAINS( - fut.ExtractValueSync(), - yexception, - "ask timeout"); - UNIT_ASSERT_VALUES_EQUAL(runtime->GetCurrentTime() - start, TDuration::Seconds(1)); - } - } -} + TDuration::Seconds(1)); + auto start = runtime->GetCurrentTime(); + runtime->DispatchEvents({}, TDuration::Seconds(5)); + UNIT_ASSERT_EXCEPTION_CONTAINS( + fut.ExtractValueSync(), + yexception, + "ask timeout"); + UNIT_ASSERT_VALUES_EQUAL(runtime->GetCurrentTime() - start, TDuration::Seconds(1)); + } + } +} |