Esempio n. 1
0
    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')
Esempio n. 2
0
    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)
Esempio n. 3
0
    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)
Esempio n. 4
0
    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')