diff options
Diffstat (limited to 'test/actor/actor_ref.test.cpp')
-rw-r--r-- | test/actor/actor_ref.test.cpp | 64 |
1 files changed, 28 insertions, 36 deletions
diff --git a/test/actor/actor_ref.test.cpp b/test/actor/actor_ref.test.cpp index 221a220ed9..0f07b87a8f 100644 --- a/test/actor/actor_ref.test.cpp +++ b/test/actor/actor_ref.test.cpp @@ -11,16 +11,12 @@ TEST(ActorRef, CanOutliveActor) { // An ActorRef can outlive its actor. Doing does not extend the actor's lifetime. // Sending a message to an ActorRef whose actor has died is a no-op. - struct Test { + struct TestActorRef { bool& died; - Test(ActorRef<Test>, bool& died_) - : died(died_) { - } + TestActorRef(ActorRef<TestActorRef>, bool& died_) : died(died_) {} - ~Test() { - died = true; - } + ~TestActorRef() { died = true; } void receive() { FAIL(); @@ -29,20 +25,19 @@ TEST(ActorRef, CanOutliveActor) { bool died = false; - ActorRef<Test> test = [&] () { - return Actor<Test>(Scheduler::GetBackground(), std::ref(died)).self(); + ActorRef<TestActorRef> test = [&]() { + return Actor<TestActorRef>(Scheduler::GetBackground(), std::ref(died)).self(); }(); EXPECT_TRUE(died); - test.invoke(&Test::receive); + test.invoke(&TestActorRef::receive); } TEST(ActorRef, Ask) { // Ask returns a Future eventually returning the result - struct Test { - - Test(ActorRef<Test>) {} + struct TestActorRef { + TestActorRef(ActorRef<TestActorRef>) {} int gimme() { return 20; @@ -53,32 +48,31 @@ TEST(ActorRef, Ask) { } }; - Actor<Test> actor(Scheduler::GetBackground()); - ActorRef<Test> ref = actor.self(); + Actor<TestActorRef> actor(Scheduler::GetBackground()); + ActorRef<TestActorRef> ref = actor.self(); - EXPECT_EQ(20, ref.ask(&Test::gimme).get()); - EXPECT_EQ(30, ref.ask(&Test::echo, 30).get()); + EXPECT_EQ(20, ref.ask(&TestActorRef::gimme).get()); + EXPECT_EQ(30, ref.ask(&TestActorRef::echo, 30).get()); } TEST(ActorRef, AskVoid) { // Ask waits for void methods - - struct Test { + + struct TestActorRef { bool& executed; - - Test(bool& executed_) : executed(executed_) { - } - + + TestActorRef(bool& executed_) : executed(executed_) {} + void doIt() { executed = true; } }; - + bool executed = false; - Actor<Test> actor(Scheduler::GetBackground(), executed); - ActorRef<Test> ref = actor.self(); - - ref.ask(&Test::doIt).get(); + Actor<TestActorRef> actor(Scheduler::GetBackground(), executed); + ActorRef<TestActorRef> ref = actor.self(); + + ref.ask(&TestActorRef::doIt).get(); EXPECT_TRUE(executed); } @@ -86,14 +80,12 @@ TEST(ActorRef, AskOnDestroyedActor) { // Tests behavior when calling ask() after the // Actor has gone away. Should set a exception_ptr. - struct Test { + struct TestActorRef { bool& died; - Test(ActorRef<Test>, bool& died_) : died(died_) {} + TestActorRef(ActorRef<TestActorRef>, bool& died_) : died(died_) {} - ~Test() { - died = true; - } + ~TestActorRef() { died = true; } int receive() { return 1; @@ -101,12 +93,12 @@ TEST(ActorRef, AskOnDestroyedActor) { }; bool died = false; - auto actor = std::make_unique<Actor<Test>>(Scheduler::GetBackground(), died); - ActorRef<Test> ref = actor->self(); + auto actor = std::make_unique<Actor<TestActorRef>>(Scheduler::GetBackground(), died); + ActorRef<TestActorRef> ref = actor->self(); actor.reset(); EXPECT_TRUE(died); - auto result = ref.ask(&Test::receive); + auto result = ref.ask(&TestActorRef::receive); EXPECT_ANY_THROW(result.get()); } |