def test_synchronize_splits(self, mocker): split_storage = InMemorySplitStorage() split_api = mocker.Mock() split_api.fetch_splits.return_value = {'splits': self.splits, 'since': 123, 'till': 123} split_sync = SplitSynchronizer(split_api, split_storage) segment_storage = InMemorySegmentStorage() segment_api = mocker.Mock() segment_api.fetch_segment.return_value = {'name': 'segmentA', 'added': ['key1', 'key2', 'key3'], 'removed': [], 'since': 123, 'till': 123} segment_sync = SegmentSynchronizer(segment_api, split_storage, segment_storage) split_synchronizers = SplitSynchronizers(split_sync, segment_sync, mocker.Mock(), mocker.Mock(), mocker.Mock()) synchronizer = Synchronizer(split_synchronizers, mocker.Mock(spec=SplitTasks)) synchronizer.synchronize_splits(123) inserted_split = split_storage.get('some_name') assert isinstance(inserted_split, Split) assert inserted_split.name == 'some_name' if not segment_sync._worker_pool.wait_for_completion(): inserted_segment = segment_storage.get('segmentA') assert inserted_segment.name == 'segmentA' assert inserted_segment.keys == {'key1', 'key2', 'key3'}
def test_storing_retrieving_splits(self, mocker): """Test storing and retrieving splits works.""" storage = InMemorySplitStorage() split = mocker.Mock(spec=Split) name_property = mocker.PropertyMock() name_property.return_value = 'some_split' type(split).name = name_property storage.put(split) assert storage.get('some_split') == split assert storage.get_split_names() == ['some_split'] assert storage.get_all_splits() == [split] assert storage.get('nonexistant_split') is None storage.remove('some_split') assert storage.get('some_split') is None
def test_kill_locally(self): """Test kill local.""" storage = InMemorySplitStorage() split = Split('some_split', 123456789, False, 'some', 'traffic_type', 'ACTIVE', 1) storage.put(split) storage.set_change_number(1) storage.kill_locally('test', 'default_treatment', 2) assert storage.get('test') is None storage.kill_locally('some_split', 'default_treatment', 0) assert storage.get('some_split').change_number == 1 assert storage.get('some_split').killed is False assert storage.get('some_split').default_treatment == 'some' storage.kill_locally('some_split', 'default_treatment', 3) assert storage.get('some_split').change_number == 3