From 8b9794b1a7276d8ea2957d5aed7169fc0b40e25d Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Mon, 18 Sep 2017 13:39:47 +0300 Subject: [core] Actor/ActorRef - ask calls to void methods - allows to wait for execution of void methods as well as non-void methods --- test/actor/actor.test.cpp | 22 ++++++++++++++++++++++ test/actor/actor_ref.test.cpp | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) (limited to 'test') diff --git a/test/actor/actor.test.cpp b/test/actor/actor.test.cpp index 4c7fc3666d..967dc152d9 100644 --- a/test/actor/actor.test.cpp +++ b/test/actor/actor.test.cpp @@ -306,6 +306,28 @@ TEST(Actor, Ask) { ASSERT_EQ(2, result.get()); } +TEST(Actor, AskVoid) { + // Ask waits for void methods + + struct Test { + bool& executed; + + Test(bool& executed_) : executed(executed_) { + } + + void doIt() { + executed = true; + } + }; + + ThreadPool pool { 1 }; + bool executed = false; + Actor actor(pool, executed); + + actor.ask(&Test::doIt).get(); + EXPECT_TRUE(executed); +} + TEST(Actor, NoSelfActorRef) { // Not all actors need a reference to self diff --git a/test/actor/actor_ref.test.cpp b/test/actor/actor_ref.test.cpp index 52b0de295b..20aa1c35c1 100644 --- a/test/actor/actor_ref.test.cpp +++ b/test/actor/actor_ref.test.cpp @@ -62,6 +62,28 @@ TEST(ActorRef, Ask) { EXPECT_EQ(30, ref.ask(&Test::echo, 30).get()); } +TEST(ActorRef, AskVoid) { + // Ask waits for void methods + + struct Test { + bool& executed; + + Test(bool& executed_) : executed(executed_) { + } + + void doIt() { + executed = true; + } + }; + + ThreadPool pool { 1 }; + bool executed = false; + Actor actor(pool, executed); + ActorRef ref = actor.self(); + + ref.ask(&Test::doIt).get(); + EXPECT_TRUE(executed); +} TEST(ActorRef, AskOnDestroyedActor) { // Tests behavior when calling ask() after the -- cgit v1.2.1