Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clarify ActorSystemMessage representation and delivery and add unit t…
…ests.
- Loading branch information
Showing
2 changed files
with
89 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import unittest | ||
import logging | ||
import time, datetime | ||
import thespian.test.helpers | ||
from thespian.actors import * | ||
from thespian.test import ActorSystemTestCase | ||
|
||
|
||
class EchoActor(Actor): | ||
def receiveMessage(self, msg, sender): | ||
logging.info('EchoActor got %s (%s) from %s', msg, type(msg), sender) | ||
self.send(sender, msg) | ||
|
||
|
||
class FakeSystemMessage(ActorSystemMessage): | ||
pass | ||
|
||
|
||
smallwait = datetime.timedelta(milliseconds=50) | ||
|
||
|
||
class TestASimpleSystem(ActorSystemTestCase): | ||
testbase='Simple' | ||
scope='func' | ||
|
||
def testCreateActorSystem(self): | ||
pass | ||
|
||
def testSimpleActor(self): | ||
echo = ActorSystem().createActor(EchoActor) | ||
|
||
def testSimpleMessageTell(self): | ||
echo = ActorSystem().createActor(EchoActor) | ||
ActorSystem().tell(echo, 'hello') | ||
time.sleep(0.02) # allow tell to work before ActorSystem shutdown | ||
|
||
def testSystemMessageTell(self): | ||
echo = ActorSystem().createActor(EchoActor) | ||
ActorSystem().tell(echo, FakeSystemMessage()) | ||
time.sleep(0.02) # allow tell to work before ActorSystem shutdown | ||
|
||
def testSimpleMessageAsk(self): | ||
echo = ActorSystem().createActor(EchoActor) | ||
self.assertEqual(ActorSystem().ask(echo, 'hello', smallwait), 'hello') | ||
|
||
def testSystemMessageAsk(self): | ||
echo = ActorSystem().createActor(EchoActor) | ||
# SystemMessages are explicitly filtered from being returned | ||
# via Ask() or Tell(), with the exception of PoisonMessage. | ||
self.assertIsNone(ActorSystem().ask(echo, FakeSystemMessage(), smallwait)) | ||
|
||
|
||
class TestMultiprocUDPSystem(TestASimpleSystem): | ||
testbase='MultiprocUDP' | ||
def setUp(self): | ||
self.setSystemBase('multiprocUDPBase') | ||
super(TestMultiprocUDPSystem, self).setUp() | ||
|
||
class TestMultiprocTCPSystem(TestASimpleSystem): | ||
testbase='MultiprocTCP' | ||
def setUp(self): | ||
self.setSystemBase('multiprocTCPBase') | ||
super(TestMultiprocTCPSystem, self).setUp() | ||
|
||
class TestMultiprocQueueSystem(TestASimpleSystem): | ||
testbase='MultiprocQueue' | ||
def setUp(self): | ||
self.setSystemBase('multiprocQueueBase') | ||
super(TestMultiprocQueueSystem, self).setUp() | ||
|