Exemplo n.º 1
0
    def test_backlog_different_ttls(self):
        """ Test if the backlog discards requests whos ttl have expired but keeps
        others.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        with patch_time() as time:
            conn.mock_connection_ready(False)

            chan.request('name', 'payload0').send(ttl=2.0)
            chan.request('name', 'payload1').send(ttl=4.0)
            chan.request('name', 'payload2').send(ttl=2.0)
            chan.request('name', 'payload3').send(ttl=4.0)

            time.sleep(3.0)

            conn.mock_connection_ready(True)

        conn.assert_upstream_verb(verbs.RequestVerb(
            name=b'name',
            unidirectional=True,
            messageref=None,
            timeout=5.0,
            payload=b'payload1'
        ))

        conn.assert_upstream_verb(verbs.RequestVerb(
            name=b'name',
            unidirectional=True,
            messageref=None,
            timeout=5.0,
            payload=b'payload3'
        ))
Exemplo n.º 2
0
    def test_backlog_no_ttl(self):
        """ Test if the backlog discards requests with no ttl at all.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        conn.mock_connection_ready(False)

        chan.request('name', 'payload0').send(ttl=0)
        chan.request('name', 'payload1').send(ttl=4.0)
        chan.request('name', 'payload2').send(ttl=0)
        chan.request('name', 'payload3').send(ttl=4.0)

        conn.mock_connection_ready(True)

        conn.assert_upstream_verb(verbs.RequestVerb(
            name=b'name',
            unidirectional=True,
            messageref=None,
            timeout=5.0,
            payload=b'payload1'
        ))

        conn.assert_upstream_verb(verbs.RequestVerb(
            name=b'name',
            unidirectional=True,
            messageref=None,
            timeout=5.0,
            payload=b'payload3'
        ))
Exemplo n.º 3
0
    def test_message_timeout_1(self):
        """ Test if a response message to a request results in the handler being called correctly.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        conn.mock_connection_ready(True)

        req = chan.request('name', 'payload')
        handler = Mock()
        req.add_handler(handler, MessageStatus.ANY)
        reqi = req.send()

        conn.mock_downstream_verb(verbs.MessageVerb(
            messageref=1,
            status=verbs.MessageVerb.STATUS_TIMEOUT,
            payload=b'response'
        ))

        self.__verify_handler_call(
            handler,
            Message,
            status=MessageStatus.TIMEOUT,
            payload=None,
            source=reqi,
        )
Exemplo n.º 4
0
    def test_post_4(self):
        """ Test if a post is discarded when connection becomes ready after the ttl is expired.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        conn.mock_connection_ready(False)

        with patch_time() as time:
            chan.request('name', 'payload').send(ttl=5.0)

            time.sleep(5.001)

            conn.mock_connection_ready(True)

        conn.assert_upstream_verb(None)
Exemplo n.º 5
0
    def test_request_1(self):
        """ Test if a request verb is pushed when the connection is ready immediately.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        conn.mock_connection_ready(True)

        chan.request('name', 'payload').send()

        conn.assert_upstream_verb(verbs.RequestVerb(
            name=b'name',
            unidirectional=True,
            messageref=None,
            timeout=5.0,
            payload=b'payload'
        ))
Exemplo n.º 6
0
    def test_backlog_order(self):
        """ Test if the order of requests is preserved when queued in the backlog.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        conn.mock_connection_ready(False)

        chan.request('name', 'payload0').send(ttl=5.0)
        chan.request('name', 'payload1').send(ttl=5.0)
        chan.request('name', 'payload2').send(ttl=5.0)

        conn.mock_connection_ready(True)

        conn.assert_upstream_verb(verbs.RequestVerb(
            name=b'name',
            unidirectional=True,
            messageref=None,
            timeout=5.0,
            payload=b'payload0'
        ))

        conn.assert_upstream_verb(verbs.RequestVerb(
            name=b'name',
            unidirectional=True,
            messageref=None,
            timeout=5.0,
            payload=b'payload1'
        ))

        conn.assert_upstream_verb(verbs.RequestVerb(
            name=b'name',
            unidirectional=True,
            messageref=None,
            timeout=5.0,
            payload=b'payload2'
        ))
Exemplo n.º 7
0
    def test_request_4(self):
        """ Test if a request is still pushed when the connection becomes ready just before
        the ttl is expires.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        with patch_time() as time:
            conn.mock_connection_ready(False)

            chan.request('name', 'payload').send(ttl=5.0)

            time.sleep(4.999)

            conn.mock_connection_ready(True)

            conn.assert_upstream_verb(verbs.RequestVerb(
                name=b'name',
                unidirectional=True,
                messageref=None,
                timeout=5.0,
                payload=b'payload'
            ))
Exemplo n.º 8
0
    def test_request_2(self):
        """ Test if the pushed request verb is unidirectional and has no messageref when no
        handlers were set.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        conn.mock_connection_ready(True)

        req = chan.request('name', 'payload')
        req.send()

        conn.assert_upstream_verb(verbs.RequestVerb(
            name=b'name',
            unidirectional=True,
            messageref=None,
            timeout=5.0,
            payload=b'payload'
        ))
Exemplo n.º 9
0
    def test_request_3(self):
        """ Test if the pushed request verb is directional and has a messsageref when a handler
        is set.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        conn.mock_connection_ready(True)

        req = chan.request('name', 'payload')
        req.add_handler(Mock())
        req.send()

        conn.assert_upstream_verb(verbs.RequestVerb(
            name=b'name',
            unidirectional=False,
            messageref=1,
            timeout=5.0,
            payload=b'payload'
        ))