예제 #1
0
    def test_blocked_connection_multiple_unblocked_in_a_row_removes_timer_once(
            self,
            connect_mock,
            add_timeout_mock,
            remove_timeout_mock):

        conn = connection.Connection(
            parameters=connection.ConnectionParameters(
                blocked_connection_timeout=60))

        # Simulate Connection.Blocked
        conn._on_connection_blocked(
            mock.Mock(name='frame.Method(Connection.Blocked)'))

        self.assertIsNotNone(conn._blocked_conn_timer)

        timer = conn._blocked_conn_timer

        # Simulate Connection.Unblocked
        conn._on_connection_unblocked(
            mock.Mock(name='frame.Method(Connection.Unblocked)'))

        # Check
        conn.remove_timeout.assert_called_once_with(timer)
        self.assertIsNone(conn._blocked_conn_timer)

        # Simulate Connection.Unblocked again
        conn._on_connection_unblocked(
            mock.Mock(name='frame.Method(Connection.Unblocked)'))

        self.assertEqual(conn.remove_timeout.call_count, 1)
        self.assertIsNone(conn._blocked_conn_timer)
예제 #2
0
 def setUp(self, connect):
     self.connection = connection.Connection()
     self.channel = mock.Mock(spec=channel.Channel)
     self.channel.is_open = True
     self.connection._channels[1] = self.channel
     self.connection._set_connection_state(
         connection.Connection.CONNECTION_OPEN)
예제 #3
0
    def test_blocked_connection_multiple_blocked_in_a_row_sets_timer_once(
            self,
            connect_mock,
            add_timeout_mock):

        conn = connection.Connection(
            parameters=connection.ConnectionParameters(
                blocked_connection_timeout=60))

        # Simulate Connection.Blocked trigger
        conn._on_connection_blocked(
            mock.Mock(name='frame.Method(Connection.Blocked)'))

        # Check
        conn.add_timeout.assert_called_once_with(
            60,
            conn._on_blocked_connection_timeout)

        self.assertIsNotNone(conn._blocked_conn_timer)

        timer = conn._blocked_conn_timer

        # Simulate Connection.Blocked trigger again
        conn._on_connection_blocked(
            mock.Mock(name='frame.Method(Connection.Blocked)'))

        self.assertEqual(conn.add_timeout.call_count, 1)
        self.assertIs(conn._blocked_conn_timer, timer)
예제 #4
0
    def setUp(self):
        with mock.patch('pika.connection.Connection.connect'):
            self.connection = connection.Connection()
            self.connection._set_connection_state(
                connection.Connection.CONNECTION_OPEN)

        self.channel = mock.Mock(spec=channel.Channel)
        self.channel.is_open = True
        self.connection._channels[1] = self.channel
예제 #5
0
    def test_create_with_blocked_connection_timeout_config(
            self, add_on_unblocked_callback_mock, add_on_blocked_callback_mock,
            connect_mock):

        conn = connection.Connection(
            parameters=connection.ConnectionParameters(
                blocked_connection_timeout=60))

        # Check
        conn.add_on_connection_blocked_callback.assert_called_once_with(
            conn._on_connection_blocked)

        conn.add_on_connection_unblocked_callback.assert_called_once_with(
            conn._on_connection_unblocked)
예제 #6
0
    def setUp(self):
        class ChannelTemplate(channel.Channel):
            channel_number = None

        with mock.patch('pika.connection.Connection.connect'):
            self.connection = connection.Connection()
            self.connection._set_connection_state(
                connection.Connection.CONNECTION_OPEN)

        self.channel = mock.Mock(spec=ChannelTemplate)
        self.channel.channel_number = 1
        self.channel.is_open = True
        self.channel.is_closing = False
        self.channel.is_closed = False
        self.connection._channels[self.channel.channel_number] = self.channel
예제 #7
0
    def test_connection_blocked_sets_timer(self, connect_mock,
                                           add_timeout_mock):

        conn = connection.Connection(
            parameters=connection.ConnectionParameters(
                blocked_connection_timeout=60))

        conn._on_connection_blocked(
            mock.Mock(name='frame.Method(Connection.Blocked)'))

        # Check
        conn.add_timeout.assert_called_once_with(
            60, conn._on_blocked_connection_timeout)

        self.assertIsNotNone(conn._blocked_conn_timer)
예제 #8
0
    def test_connect_no_adapter_connect_from_constructor(self):
        """check that adapter connection with AMQP is not happening in constructor """
        with mock.patch('pika.connection.Connection._adapter_connect',
                        return_value=Exception('_adapter_connect failed')
                        ) as adapter_connect_mock:
            with mock.patch('pika.connection.Connection.add_timeout',
                            return_value='timer') as add_timeout_mock:
                conn = connection.Connection()

                self.assertFalse(adapter_connect_mock.called)

                self.assertEqual(conn.connection_state, conn.CONNECTION_INIT)

                self.assertIsNotNone(conn._connection_attempt_timer)

                add_timeout_mock.assert_called_once_with(0,
                                                         conn._on_connect_timer)
예제 #9
0
    def test_blocked_connection_timeout_teminates_connection(
            self, connect_mock, add_timeout_mock, on_terminate_mock):

        conn = connection.Connection(
            parameters=connection.ConnectionParameters(
                blocked_connection_timeout=60))

        conn._on_connection_blocked(
            mock.Mock(name='frame.Method(Connection.Blocked)'))

        conn._on_blocked_connection_timeout()

        # Check
        conn._on_terminate.assert_called_once_with(
            connection.InternalCloseReasons.BLOCKED_CONNECTION_TIMEOUT,
            'Blocked connection timeout expired')

        self.assertIsNone(conn._blocked_conn_timer)
예제 #10
0
    def test_blocked_connection_on_terminate_removes_timer(
            self, adapter_disconnect_mock, connect_mock, add_timeout_mock,
            remove_timeout_mock):

        conn = connection.Connection(
            parameters=connection.ConnectionParameters(
                blocked_connection_timeout=60))

        conn._on_connection_blocked(
            mock.Mock(name='frame.Method(Connection.Blocked)'))

        self.assertIsNotNone(conn._blocked_conn_timer)

        timer = conn._blocked_conn_timer

        conn._on_terminate(0, 'test_on_terminate_removes_timer')

        # Check
        conn.remove_timeout.assert_called_once_with(timer)
        self.assertIsNone(conn._blocked_conn_timer)
예제 #11
0
    def test_client_properties_override(self):
        expectation = {
            'capabilities': {
                'authentication_failure_close': True,
                'basic.nack': True,
                'connection.blocked': True,
                'consumer_cancel_notify': True,
                'publisher_confirms': True
            }
        }
        override = {'product': 'My Product',
                    'platform': 'Your platform',
                    'version': '0.1',
                    'information': 'this is my app'}
        expectation.update(override)

        params = connection.ConnectionParameters(client_properties=override)

        with mock.patch('pika.connection.Connection.connect'):
            conn = connection.Connection(params)
            self.assertDictEqual(conn._client_properties, expectation)
예제 #12
0
 def test_new_conn_should_use_first_channel(self, connect):
     """_next_channel_number in new conn should always be 1"""
     conn = connection.Connection()
     self.assertEqual(1, conn._next_channel_number())