Skip to content

Updated tests #562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions splitio/client/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@
from splitio.storage.inmemmory import InMemorySplitStorage, InMemorySegmentStorage, \
InMemoryImpressionStorage, InMemoryEventStorage, InMemoryTelemetryStorage, LocalhostTelemetryStorage, \
InMemorySplitStorageAsync, InMemorySegmentStorageAsync, InMemoryImpressionStorageAsync, \
InMemoryEventStorageAsync, InMemoryTelemetryStorageAsync, LocalhostTelemetryStorageAsync
InMemoryEventStorageAsync, InMemoryTelemetryStorageAsync, LocalhostTelemetryStorageAsync, \
InMemoryRuleBasedSegmentStorage, InMemoryRuleBasedSegmentStorageAsync
from splitio.storage.adapters import redis
from splitio.storage.redis import RedisSplitStorage, RedisSegmentStorage, RedisImpressionsStorage, \
RedisEventsStorage, RedisTelemetryStorage, RedisSplitStorageAsync, RedisEventsStorageAsync,\
RedisSegmentStorageAsync, RedisImpressionsStorageAsync, RedisTelemetryStorageAsync
RedisSegmentStorageAsync, RedisImpressionsStorageAsync, RedisTelemetryStorageAsync, \
RedisRuleBasedSegmentsStorage, RedisRuleBasedSegmentsStorageAsync
from splitio.storage.pluggable import PluggableEventsStorage, PluggableImpressionsStorage, PluggableSegmentStorage, \
PluggableSplitStorage, PluggableTelemetryStorage, PluggableTelemetryStorageAsync, PluggableEventsStorageAsync, \
PluggableImpressionsStorageAsync, PluggableSegmentStorageAsync, PluggableSplitStorageAsync
PluggableImpressionsStorageAsync, PluggableSegmentStorageAsync, PluggableSplitStorageAsync, \
PluggableRuleBasedSegmentsStorage, PluggableRuleBasedSegmentsStorageAsync

# APIs
from splitio.api.client import HttpClient, HttpClientAsync, HttpClientKerberos
Expand Down Expand Up @@ -543,6 +546,7 @@ def _build_in_memory_factory(api_key, cfg, sdk_url=None, events_url=None, # pyl
storages = {
'splits': InMemorySplitStorage(cfg['flagSetsFilter'] if cfg['flagSetsFilter'] is not None else []),
'segments': InMemorySegmentStorage(),
'rule_based_segments': InMemoryRuleBasedSegmentStorage(),
'impressions': InMemoryImpressionStorage(cfg['impressionsQueueSize'], telemetry_runtime_producer),
'events': InMemoryEventStorage(cfg['eventsQueueSize'], telemetry_runtime_producer),
}
Expand All @@ -559,7 +563,7 @@ def _build_in_memory_factory(api_key, cfg, sdk_url=None, events_url=None, # pyl
imp_strategy, none_strategy, telemetry_runtime_producer)

synchronizers = SplitSynchronizers(
SplitSynchronizer(apis['splits'], storages['splits']),
SplitSynchronizer(apis['splits'], storages['splits'], storages['rule_based_segments']),
SegmentSynchronizer(apis['segments'], storages['splits'], storages['segments']),
ImpressionSynchronizer(apis['impressions'], storages['impressions'],
cfg['impressionsBulkSize']),
Expand Down Expand Up @@ -671,6 +675,7 @@ async def _build_in_memory_factory_async(api_key, cfg, sdk_url=None, events_url=
storages = {
'splits': InMemorySplitStorageAsync(cfg['flagSetsFilter'] if cfg['flagSetsFilter'] is not None else []),
'segments': InMemorySegmentStorageAsync(),
'rule_based_segments': InMemoryRuleBasedSegmentStorageAsync(),
'impressions': InMemoryImpressionStorageAsync(cfg['impressionsQueueSize'], telemetry_runtime_producer),
'events': InMemoryEventStorageAsync(cfg['eventsQueueSize'], telemetry_runtime_producer),
}
Expand All @@ -687,7 +692,7 @@ async def _build_in_memory_factory_async(api_key, cfg, sdk_url=None, events_url=
imp_strategy, none_strategy, telemetry_runtime_producer)

synchronizers = SplitSynchronizers(
SplitSynchronizerAsync(apis['splits'], storages['splits']),
SplitSynchronizerAsync(apis['splits'], storages['splits'], storages['rule_based_segments']),
SegmentSynchronizerAsync(apis['segments'], storages['splits'], storages['segments']),
ImpressionSynchronizerAsync(apis['impressions'], storages['impressions'],
cfg['impressionsBulkSize']),
Expand Down Expand Up @@ -756,6 +761,7 @@ def _build_redis_factory(api_key, cfg):
storages = {
'splits': RedisSplitStorage(redis_adapter, cache_enabled, cache_ttl, []),
'segments': RedisSegmentStorage(redis_adapter),
'rule_based_segments': RedisRuleBasedSegmentsStorage(redis_adapter),
'impressions': RedisImpressionsStorage(redis_adapter, sdk_metadata),
'events': RedisEventsStorage(redis_adapter, sdk_metadata),
'telemetry': RedisTelemetryStorage(redis_adapter, sdk_metadata)
Expand Down Expand Up @@ -839,6 +845,7 @@ async def _build_redis_factory_async(api_key, cfg):
storages = {
'splits': RedisSplitStorageAsync(redis_adapter, cache_enabled, cache_ttl),
'segments': RedisSegmentStorageAsync(redis_adapter),
'rule_based_segments': RedisRuleBasedSegmentsStorageAsync(redis_adapter),
'impressions': RedisImpressionsStorageAsync(redis_adapter, sdk_metadata),
'events': RedisEventsStorageAsync(redis_adapter, sdk_metadata),
'telemetry': await RedisTelemetryStorageAsync.create(redis_adapter, sdk_metadata)
Expand Down Expand Up @@ -922,6 +929,7 @@ def _build_pluggable_factory(api_key, cfg):
storages = {
'splits': PluggableSplitStorage(pluggable_adapter, storage_prefix, []),
'segments': PluggableSegmentStorage(pluggable_adapter, storage_prefix),
'rule_based_segments': PluggableRuleBasedSegmentsStorage(pluggable_adapter, storage_prefix),
'impressions': PluggableImpressionsStorage(pluggable_adapter, sdk_metadata, storage_prefix),
'events': PluggableEventsStorage(pluggable_adapter, sdk_metadata, storage_prefix),
'telemetry': PluggableTelemetryStorage(pluggable_adapter, sdk_metadata, storage_prefix)
Expand Down Expand Up @@ -1003,6 +1011,7 @@ async def _build_pluggable_factory_async(api_key, cfg):
storages = {
'splits': PluggableSplitStorageAsync(pluggable_adapter, storage_prefix),
'segments': PluggableSegmentStorageAsync(pluggable_adapter, storage_prefix),
'rule_based_segments': PluggableRuleBasedSegmentsStorageAsync(pluggable_adapter, storage_prefix),
'impressions': PluggableImpressionsStorageAsync(pluggable_adapter, sdk_metadata, storage_prefix),
'events': PluggableEventsStorageAsync(pluggable_adapter, sdk_metadata, storage_prefix),
'telemetry': await PluggableTelemetryStorageAsync.create(pluggable_adapter, sdk_metadata, storage_prefix)
Expand Down Expand Up @@ -1081,13 +1090,15 @@ def _build_localhost_factory(cfg):
storages = {
'splits': InMemorySplitStorage(cfg['flagSetsFilter'] if cfg['flagSetsFilter'] is not None else []),
'segments': InMemorySegmentStorage(), # not used, just to avoid possible future errors.
'rule_based_segments': InMemoryRuleBasedSegmentStorage(),
'impressions': LocalhostImpressionsStorage(),
'events': LocalhostEventsStorage(),
}
localhost_mode = LocalhostMode.JSON if cfg['splitFile'][-5:].lower() == '.json' else LocalhostMode.LEGACY
synchronizers = SplitSynchronizers(
LocalSplitSynchronizer(cfg['splitFile'],
storages['splits'],
storages['rule_based_segments'],
localhost_mode),
LocalSegmentSynchronizer(cfg['segmentDirectory'], storages['splits'], storages['segments']),
None, None, None,
Expand Down Expand Up @@ -1151,13 +1162,15 @@ async def _build_localhost_factory_async(cfg):
storages = {
'splits': InMemorySplitStorageAsync(),
'segments': InMemorySegmentStorageAsync(), # not used, just to avoid possible future errors.
'rule_based_segments': InMemoryRuleBasedSegmentStorageAsync(),
'impressions': LocalhostImpressionsStorageAsync(),
'events': LocalhostEventsStorageAsync(),
}
localhost_mode = LocalhostMode.JSON if cfg['splitFile'][-5:].lower() == '.json' else LocalhostMode.LEGACY
synchronizers = SplitSynchronizers(
LocalSplitSynchronizerAsync(cfg['splitFile'],
storages['splits'],
storages['rule_based_segments'],
localhost_mode),
LocalSegmentSynchronizerAsync(cfg['segmentDirectory'], storages['splits'], storages['segments']),
None, None, None,
Expand Down
2 changes: 1 addition & 1 deletion splitio/sync/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def _sanitize_condition(self, feature_flag):
{ "treatment": "off", "size": 100 }
],
"label": "default rule"
})
})

return feature_flag

Expand Down
4 changes: 2 additions & 2 deletions tests/api/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_auth(self, mocker):
call_made = httpclient.get.mock_calls[0]

# validate positional arguments
assert call_made[1] == ('auth', 'v2/auth?s=1.1', 'some_api_key')
assert call_made[1] == ('auth', 'v2/auth?s=1.3', 'some_api_key')

# validate key-value args (headers)
assert call_made[2]['extra_headers'] == {
Expand Down Expand Up @@ -89,7 +89,7 @@ async def get(verb, url, key, extra_headers):

# validate positional arguments
assert self.verb == 'auth'
assert self.url == 'v2/auth?s=1.1'
assert self.url == 'v2/auth?s=1.3'
assert self.key == 'some_api_key'
assert self.headers == {
'SplitSDKVersion': 'python-%s' % __version__,
Expand Down
12 changes: 6 additions & 6 deletions tests/api/test_splits_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_fetch_split_changes(self, mocker):
'SplitSDKMachineIP': '1.2.3.4',
'SplitSDKMachineName': 'some'
},
query={'s': '1.1', 'since': 123, 'rbSince': -1, 'sets': 'set1,set2'})]
query={'s': '1.3', 'since': 123, 'rbSince': -1, 'sets': 'set1,set2'})]

httpclient.reset_mock()
response = split_api.fetch_splits(123, 1, FetchOptions(True, 123, None,'set3'))
Expand All @@ -36,7 +36,7 @@ def test_fetch_split_changes(self, mocker):
'SplitSDKMachineName': 'some',
'Cache-Control': 'no-cache'
},
query={'s': '1.1', 'since': 123, 'rbSince': 1, 'till': 123, 'sets': 'set3'})]
query={'s': '1.3', 'since': 123, 'rbSince': 1, 'till': 123, 'sets': 'set3'})]

httpclient.reset_mock()
response = split_api.fetch_splits(123, 122, FetchOptions(True, 123, None, 'set3'))
Expand All @@ -48,7 +48,7 @@ def test_fetch_split_changes(self, mocker):
'SplitSDKMachineName': 'some',
'Cache-Control': 'no-cache'
},
query={'s': '1.1', 'since': 123, 'rbSince': 122, 'till': 123, 'sets': 'set3'})]
query={'s': '1.3', 'since': 123, 'rbSince': 122, 'till': 123, 'sets': 'set3'})]

httpclient.reset_mock()
def raise_exception(*args, **kwargs):
Expand Down Expand Up @@ -92,7 +92,7 @@ async def get(verb, url, key, query, extra_headers):
'SplitSDKMachineIP': '1.2.3.4',
'SplitSDKMachineName': 'some'
}
assert self.query == {'s': '1.1', 'since': 123, 'rbSince': -1, 'sets': 'set1,set2'}
assert self.query == {'s': '1.3', 'since': 123, 'rbSince': -1, 'sets': 'set1,set2'}

httpclient.reset_mock()
response = await split_api.fetch_splits(123, 1, FetchOptions(True, 123, None, 'set3'))
Expand All @@ -106,7 +106,7 @@ async def get(verb, url, key, query, extra_headers):
'SplitSDKMachineName': 'some',
'Cache-Control': 'no-cache'
}
assert self.query == {'s': '1.1', 'since': 123, 'rbSince': 1, 'till': 123, 'sets': 'set3'}
assert self.query == {'s': '1.3', 'since': 123, 'rbSince': 1, 'till': 123, 'sets': 'set3'}

httpclient.reset_mock()
response = await split_api.fetch_splits(123, 122, FetchOptions(True, 123, None))
Expand All @@ -120,7 +120,7 @@ async def get(verb, url, key, query, extra_headers):
'SplitSDKMachineName': 'some',
'Cache-Control': 'no-cache'
}
assert self.query == {'s': '1.1', 'since': 123, 'rbSince': 122, 'till': 123}
assert self.query == {'s': '1.3', 'since': 123, 'rbSince': 122, 'till': 123}

httpclient.reset_mock()
def raise_exception(*args, **kwargs):
Expand Down
Loading