def test_agent_shutdown(nsproxy): """ An agent must unregister itself before shutting down. """ agent = AgentProcess('a0', nsproxy.addr()) agent.start() a0 = Proxy('a0', nsproxy.addr()) a0.run() assert 'a0' in nsproxy.list() a0.shutdown() agent.join() assert 'a0' not in nsproxy.list()
def test_nameserver_proxy_shutdown_with_pyroerror(): """ Check that `PyroError`s raised during `async_nameserver_shutdown` are handled correctly. """ nameserver = run_nameserver() ap = AgentProcess() name = ap.start() proxy = Proxy(name) proxy.run() ap.kill() nameserver.async_shutdown_agents(nameserver.addr()) nameserver.shutdown()
def test_agent_inheritance(nsproxy): """ Test agent inheritance; agents can be based on a custom class. """ class NewAgent(Agent): def the_answer_to_life(self): return 42 # Test an Agent based on the new class AgentProcess('new', nsaddr=nsproxy.addr(), base=NewAgent).start() new = Proxy('new', nsproxy.addr()) new.run() assert new.the_answer_to_life() == 42 # Test the quick `run_agent` function a0 = run_agent('a0', nsproxy.addr(), base=NewAgent) assert a0.the_answer_to_life() == 42