def test_run_agent(): """Test that we can set up and then run the agent.""" with LocalNode() as node: agent_name = "dummyagent" agent_address = "some_address" identity = Identity(agent_name, address=agent_address) oef_local_connection = _make_local_connection(agent_address, node) oef_local_connection._local_node = node agent = DummyAgent(identity, [oef_local_connection],) assert agent.name == identity.name assert agent.tick == 0 assert ( agent.agent_state == AgentState.INITIATED ), "Agent state must be 'initiated'" agent.multiplexer.connect() assert ( agent.agent_state == AgentState.CONNECTED ), "Agent state must be 'connected'" assert isinstance(agent.inbox, InBox) assert isinstance(agent.outbox, OutBox) agent_thread = Thread(target=agent.start) agent_thread.start() time.sleep(1.0) try: assert ( agent.agent_state == AgentState.RUNNING ), "Agent state must be 'running'" finally: agent.stop() agent.multiplexer.disconnect() agent_thread.join()
def test_run_agent(): """Test that we can set up and then run the agent.""" with LocalNode() as node: agent_name = "dummyagent" agent_address = "some_address" identity = Identity(agent_name, address=agent_address) oef_local_connection = _make_local_connection(agent_address, node) oef_local_connection._local_node = node agent = DummyAgent(identity, [oef_local_connection], loop=asyncio.new_event_loop()) agent_thread = Thread(target=agent.start) assert agent.state == RuntimeStates.stopped agent_thread.start() try: wait_for_condition( lambda: agent.state == RuntimeStates.starting, timeout=10, error_msg="Agent state must be 'starting'", ) wait_for_condition( lambda: agent.state == RuntimeStates.running, timeout=10, error_msg="Agent state must be 'running'", ) finally: agent.stop() assert agent.state == RuntimeStates.stopped agent_thread.join()
def test_run_agent(): """Test that we can set up and then run the agent.""" with LocalNode() as node: agent_name = "dummyagent" agent_address = "some_address" identity = Identity(agent_name, address=agent_address) oef_local_connection = _make_local_connection(agent_address, node) oef_local_connection._local_node = node agent = DummyAgent( identity, [oef_local_connection], ) assert agent.name == identity.name assert agent.tick == 0 assert (agent.agent_state == AgentState.INITIATED ), "Agent state must be 'initiated'" agent.multiplexer.connect() assert (agent.agent_state == AgentState.CONNECTED ), "Agent state must be 'connected'" assert isinstance(agent.inbox, InBox) assert isinstance(agent.outbox, OutBox) agent.multiplexer.disconnect() import asyncio agent = DummyAgent(identity, [oef_local_connection], loop=asyncio.new_event_loop()) agent_thread = Thread(target=agent.start) agent_thread.start() try: wait_for_condition( lambda: agent._main_loop and agent._main_loop.is_running, timeout=5, error_msg="Agent loop not started!'", ) wait_for_condition( lambda: agent.agent_state == AgentState.RUNNING, timeout=5, error_msg="Agent state must be 'running'", ) finally: agent.stop() agent_thread.join()
def test_runtime_modes(): """Test runtime modes are set.""" agent_name = "dummyagent" agent_address = "some_address" identity = Identity(agent_name, address=agent_address) agent = DummyAgent( identity, [], ) assert not agent.is_running assert agent.is_stopped agent._runtime_mode = "not exists" with pytest.raises(ValueError): agent._get_runtime_class() with pytest.raises(ValueError): agent.runtime._get_agent_loop_class("not exists") assert agent.runtime.loop_mode == agent.runtime.DEFAULT_RUN_LOOP