Beispiel #1
0
    def test_get_all_splits(self, mocker):
        """Test fetching all splits."""
        uwsgi = get_uwsgi(True)
        storage = UWSGISplitStorage(uwsgi)
        split_1 = mocker.Mock(spec=Split)
        split_1.to_json.return_value = '{"name": "some_split_1"}'
        split_name_1 = mocker.PropertyMock()
        split_name_1.return_value = 'some_split_1'
        type(split_1).name = split_name_1
        split_2 = mocker.Mock(spec=Split)
        split_2.to_json.return_value = '{"name": "some_split_2"}'
        split_name_2 = mocker.PropertyMock()
        split_name_2.return_value = 'some_split_2'
        type(split_2).name = split_name_2

        def _from_raw_mock(split_json):
            split_mock = mocker.Mock(spec=Split)
            name = mocker.PropertyMock()
            name.return_value = json.loads(split_json)['name']
            type(split_mock).name = name
            return split_mock
        mocker.patch('splitio.storage.uwsgi.splits.from_raw', new=_from_raw_mock)

        storage.put(split_1)
        storage.put(split_2)

        splits = storage.get_all_splits()
        s1 = next(split for split in splits if split.name == 'some_split_1')
        s2 = next(split for split in splits if split.name == 'some_split_2')
def uwsgi_update_segments(user_config):
    """
    Update segments task.

    :param user_config: User-provided configuration.
    :type user_config: dict
    """
    config = _get_config(user_config)
    seconds = config['segmentsRefreshRate']
    segment_sync_task = SegmentSynchronizationTask(
        SegmentsAPI(
            HttpClient(1500, config.get('sdk_url'), config.get('events_url')),
            config['apikey']),
        UWSGISegmentStorage(get_uwsgi()),
        None,  # Split sotrage not needed, segments provided manually,
        None,  # Period not needed, task executed manually
        None  # Flag not needed, never consumed or set.
    )

    pool = workerpool.WorkerPool(20, segment_sync_task._update_segment)  #pylint: disable=protected-access
    pool.start()
    split_storage = UWSGISplitStorage(get_uwsgi())
    while True:
        try:
            for split in split_storage.get_all_splits():
                for segment_name in split.get_segment_names():
                    pool.submit_work(segment_name)
            time.sleep(seconds)
        except Exception:  #pylint: disable=broad-except
            _LOGGER.error('Error updating segments')
            _LOGGER.debug('Error: ', exc_info=True)
Beispiel #3
0
    def test_get_all_splits(self, mocker):
        """Test fetching all splits."""
        uwsgi = get_uwsgi(True)
        storage = UWSGISplitStorage(uwsgi)
        from_raw_mock = self._get_from_raw_mock(mocker)
        mocker.patch('splitio.models.splits.from_raw', new=from_raw_mock)

        split_1 = from_raw_mock({'name': 'some_split_1', 'trafficTypeName': 'user'})
        split_2 = from_raw_mock({'name': 'some_split_2', 'trafficTypeName': 'user'})
        storage.put(split_1)
        storage.put(split_2)

        splits = storage.get_all_splits()
        s1 = next(split for split in splits if split.name == 'some_split_1')
        s2 = next(split for split in splits if split.name == 'some_split_2')

        assert s1.traffic_type_name == 'user'
        assert s2.traffic_type_name == 'user'