Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_raise_no_trap_exit(self):
collectingActor1 = actor_of(CollectingActor)
collectingActor1.trap_exit = False
collectingActor1.start()
collectingActor2 = actor_of(CollectingActor)
collectingActor2.trap_exit = False
collectingActor2.start()
collectingActor3 = actor_of(CollectingActor)
collectingActor3.trap_exit = True
collectingActor3.start()
collectingActor4 = actor_of(CollectingActor)
collectingActor4.trap_exit = True
collectingActor4.start()
raisingActor = actor_of(RaisingActor)
raisingActor.link(collectingActor1)
collectingActor1.link(collectingActor2)
collectingActor2.link(collectingActor3)
collectingActor3.link(collectingActor4)
raisingActor.start()
raisingActor.notify("Msg")
def test_unhandled(self):
actor = actor_of(Dispatcher)
actor.start()
res = actor.query("unhandled")
self.assertEqual(type(res.get()), str)
actor.stop()
def test_remote(self):
remote = RemoteConnection().start_listener("localhost", 0)
remote.register("main-actor", actor_of(MultiplyingActor))
remote.start_all()
# port is dynamic
port = remote.listener.socket.port
client1 = RemoteConnection().actor_for("main-actor", "localhost", port)
res = client1.query("mult", [1, 2, 3, 4])
self.assertEqual(res.get(timeout=3), 24)
# check, that I can use another client
client2 = RemoteConnection().actor_for("main-actor", "localhost", port)
res = client2.query("mult", [4, 4, 4])
self.assertEqual(res.get(timeout=3), 64)
# check, that the first still works
res = client1.query("mult", [2, 2, 4])
def test_docstring_request(self):
actor = actor_of(Dispatcher)
actor.start()
res = actor.query("?get_docstring")
self.assertEqual(res.get(), " This method has no content but a docstring. ")
actor.stop()
def test_simply_reply(self):
actor_ref = actor_of(MultiplyingActor)
actor_ref.start()
res = actor_ref.query("mult", [1, 2, 3, 4])
self.assertEqual(res.get(timeout=3), 24)
actor_ref.stop()
#assert False
def __init__(self, team_name):
self.team_name = team_name
self.actor_ref = actor_of(_ClientActor)
self.actor_ref._actor.thread.daemon = True # TODO remove this line
self.actor_ref.start()
def __init__(self, viewer):
self.actor_ref = actor_of(_ViewerActor)
self.actor_ref._actor.thread.daemon = True # TODO remove this line
self.actor_ref.start()
self._set_viewer(viewer)
def _startup(self):
""" Instantiates the ServerActor and initialises a new game.
"""
self.server = actor_of(ServerActor, "pelita-main")
if self.port is not None:
if not self.silent:
print "Starting remote connection on %s:%s" % (self.host, self.port)
self.remote = RemoteConnection().start_listener(host=self.host, port=self.port)
self.remote.register("pelita-main", self.server)
self.remote.start_all()
else:
if not self.silent:
print "Starting actor '%s'" % "pelita-main"
self.server.start()
# Begin code for automatic closing the server when a game has run
# TODO: this is bit of a hack and should be done by linking
# the actors/remote connection.
import logging
#logging.basicConfig()
remote = True
if remote:
remote = RemoteConnection().start_listener("localhost", 0)
remote.register("ping", actor_of(Ping))
remote.start_all()
port = remote.listener.socket.port
ping = RemoteConnection().actor_for("ping", "localhost", port)
else:
ping = actor_of(Ping)
ping.start()
pong = actor_of(Pong)
pong.start()
ping.notify("connect", [pong.uuid])
ping.notify("Start")
pong.join()
if remote:
remote.stop()
else:
ping.stop()
pong.stop()