def test_get_desired_instance_count_based_on_current_queue_length(
            self, mock_boto3):
        self.input_attrs['queues'] = ['queue1', 'queue2']

        sqs_client = mock_boto3.client.return_value
        sqs_client.get_queue_attributes.side_effect = [
            {
                'Attributes': {
                    'ApproximateNumberOfMessages': '400'
                }
            },
            {
                'Attributes': {
                    'ApproximateNumberOfMessages': '350'
                }
            },
        ]

        sqs_scaler = SqsScaler(app_name, min_instances, max_instances,
                               **self.input_attrs)
        sqs_scaler.statsd_client = Mock()
        assert sqs_scaler._get_desired_instance_count_based_on_current_queue_length(
        ) == 3
        calls = [
            call("testqueue1.queue-length", 400),
            call("testqueue2.queue-length", 350),
        ]
        sqs_scaler.statsd_client.gauge.assert_has_calls(calls)
Пример #2
0
    def test_sqs_client_initialization(self, mock_boto3):
        self.input_attrs['queues'] = ['queue1', 'queue2']
        mock_client = mock_boto3.client
        sqs_scaler = SqsScaler(**self.input_attrs)
        sqs_scaler.statsd_client = Mock()

        assert sqs_scaler.sqs_client is None
        sqs_scaler.get_desired_instance_count()
        assert sqs_scaler.sqs_client == mock_client.return_value
        mock_client.assert_called_with('sqs', region_name='eu-west-1')
    def test_client_initialization(self, mock_boto3):
        self.input_attrs['queues'] = ['queue1', 'queue2']
        mock_client = mock_boto3.client
        sqs_scaler = SqsScaler(app_name, min_instances, max_instances, **self.input_attrs)
        sqs_scaler.statsd_client = Mock()

        assert sqs_scaler.sqs_client is None
        assert sqs_scaler.cloudwatch_client is None
        sqs_scaler.get_desired_instance_count()
        assert sqs_scaler.sqs_client == mock_client.return_value
        assert sqs_scaler.cloudwatch_client == mock_client.return_value
        calls = [
            call('sqs', region_name='eu-west-1'),
            call('cloudwatch', region_name='eu-west-1'),
        ]
        for x in calls:
            assert x in mock_client.call_args_list