(Unit)Testing Actors

2 views
Skip to first unread message

Javier

unread,
May 3, 2011, 7:55:45 PM5/3/11
to pysage
Gents,

Which is the best way to test actors?

Currently, I doing something like the following:

class WorkersManagerTest(Actor, unittest.TestCase):
"""Act as a DirectoryService to see if workers request work."""

subscriptions = [ 'AccessPointRequest' ]

def __init__(self, *args, **kwargs):
unittest.TestCase.__init__(self, *args, **kwargs)
Actor.__init__(self)

def setUp(self):
mgr.register_actor(self)

self._current_workermanager = None
self._requests = 0

def tearDown(self):
mgr.unregister_actor(self)
if self._current_workermanager:
mgr.unregister_actor(self._current_workermanager)

def handle_AccessPointRequest(self, msg):
self._requests += 1

def test_workers_are_started(self):
max_workers = 10
self._current_workermanager =
log_fetcher.WorkersManager(max_workers,
MockWorker)
mgr.register_actor(self._current_workermanager)

[...]

John Yang

unread,
May 3, 2011, 11:54:30 PM5/3/11
to pys...@googlegroups.com
Hi Javier:

Have a look at pysage's own unit test:

http://code.google.com/p/pysage/source/browse/trunk/tests/test_system.py

Here's a test module that spawns child processes:

http://code.google.com/p/pysage/source/browse/trunk/tests/test_groups_process.py

Does this help?

John

> --
> You received this message because you are subscribed to the Google Groups "pysage" group.
> To post to this group, send email to pys...@googlegroups.com.
> To unsubscribe from this group, send email to pysage+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pysage?hl=en.
>
>

Javier Ruere

unread,
May 4, 2011, 10:31:10 AM5/4/11
to pys...@googlegroups.com
Yep, thanks.

I've fixed the setUp & tearDown methods and will rework the test case
to use separate actors instead of being an actor itself.

Javier

Reply all
Reply to author
Forward
0 new messages