def test_addresses_are_not_shared_accross_instances(self): comm1 = InProcessCommunicationLayer() comm1.discovery = Discovery('a1', 'addr1') comm2 = InProcessCommunicationLayer() comm2.discovery = Discovery('a2', 'addr2') comm1.discovery.register_agent('a1', comm1) with pytest.raises(UnknownAgent): comm2.discovery.agent_address('a1')
def test_raise_when_sending_to_unknown_agent_fail_on_send(self): comm1 = InProcessCommunicationLayer() comm1.discovery = Discovery('a1', comm1) full_msg = ('c1', 'c2', 'msg') with pytest.raises(UnknownAgent): comm1.send_msg('a1', 'a2', full_msg, on_error='fail')
def test_msg_to_another_agent(self): comm1 = InProcessCommunicationLayer() Messaging('a1', comm1) comm1.discovery = Discovery('a1', comm1) comm2 = InProcessCommunicationLayer() Messaging('a2', comm2) comm2.discovery = Discovery('a2', comm2) comm2.receive_msg = MagicMock() comm1.discovery.register_agent('a2', comm2) full_msg = ('c1', 'c2', 'msg') comm1.send_msg('a1', 'a2', full_msg) comm2.receive_msg.assert_called_with('a1', 'a2', full_msg)
def test_retry_when_sending_to_unknown_agent_retry_on_send(self): comm1 = InProcessCommunicationLayer(None) comm1.discovery = Discovery('a1', comm1) full_msg = ('c1', 'c2', 'msg') assert not comm1.send_msg('a1', 'a2', full_msg, on_error='retry') comm2 = create_autospec(InProcessCommunicationLayer) comm1.discovery.register_agent('a2', comm2) comm2.receive_msg.assert_called_with('a1', 'a2', full_msg)
def local_messaging(): comm = InProcessCommunicationLayer() comm.discovery = Discovery('a1', 'addr1') messaging = Messaging('a1', comm) return messaging
def test_ignore_when_sending_to_unknown_agent_ignore_on_send(self): comm1 = InProcessCommunicationLayer() comm1.discovery = Discovery('a1', comm1) full_msg = ('c1', 'c2', 'msg') assert comm1.send_msg('a1', 'a2', full_msg, on_error='ignore')