Skip to content

Commit ca37770

Browse files
committed
Removed BUR from localhost legacy and yaml
1 parent 5524304 commit ca37770

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

splitio/client/factory.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from splitio.sync.synchronizer import SplitTasks, SplitSynchronizers, Synchronizer, \
4848
LocalhostSynchronizer, RedisSynchronizer
4949
from splitio.sync.manager import Manager, RedisManager
50-
from splitio.sync.split import SplitSynchronizer, LocalSplitSynchronizer, LocalhostMode
50+
from splitio.sync.split import SplitSynchronizer, LocalSplitSynchronizer, LocalhostMode, _ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES
5151
from splitio.sync.segment import SegmentSynchronizer, LocalSegmentSynchronizer
5252
from splitio.sync.impression import ImpressionSynchronizer, ImpressionsCountSynchronizer
5353
from splitio.sync.event import EventSynchronizer
@@ -555,8 +555,13 @@ def _build_localhost_factory(cfg):
555555
ready_event = threading.Event()
556556
synchronizer = LocalhostSynchronizer(synchronizers, tasks)
557557
manager = Manager(ready_event, synchronizer, None, False, sdk_metadata, telemetry_runtime_producer)
558-
initialization_thread = threading.Thread(target=manager.start, name="SDKInitializer", daemon=True)
559-
initialization_thread.start()
558+
559+
# TODO: BUR is only applied for Localhost JSON mode, in future legacy and yaml will also use BUR
560+
if localhost_mode == LocalhostMode.JSON:
561+
initialization_thread = threading.Thread(target=manager.start, args = [_ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES], name="SDKInitializer", daemon=True)
562+
initialization_thread.start()
563+
else:
564+
manager.start(1)
560565

561566
recorder = StandardRecorder(
562567
ImpressionsManager(StrategyDebugMode(), telemetry_runtime_producer),

splitio/sync/synchronizer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def sync_all(self, till=None):
512512
Synchronize all splits.
513513
"""
514514
self._backoff.reset()
515-
remaining_attempts = _ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES
515+
remaining_attempts = _ON_DEMAND_FETCH_BACKOFF_MAX_RETRIES if till == None else till
516516
while remaining_attempts > 0:
517517
remaining_attempts -= 1
518518
try:
@@ -521,6 +521,10 @@ def sync_all(self, till=None):
521521
_LOGGER.error('Failed syncing all')
522522
_LOGGER.error(str(exc))
523523

524+
# TODO: to be removed when legacy use BUR
525+
if till == 1: # Legacy mode
526+
raise Exception("Failed to fetch Splits")
527+
524528
how_long = self._backoff.get()
525529
time.sleep(how_long)
526530

tests/integration/test_client_e2e.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,11 +1069,24 @@ def _synchronize_now(self):
10691069
self.factory._sync_manager._synchronizer._split_synchronizers._split_sync.synchronize_splits()
10701070

10711071
def test_incorrect_file_e2e(self):
1072-
factory = get_factory('localhost', config={'splitFile': 'filename'})
1072+
"""Test initialize factory with a incorrect file name."""
1073+
# TODO: secontion below is removed when legacu use BUR
1074+
# legacy and yaml
1075+
exception_raised = False
1076+
factory = None
1077+
try:
1078+
factory = get_factory('localhost', config={'splitFile': 'filename'})
1079+
except Exception as e:
1080+
exception_raised = True
1081+
1082+
assert(exception_raised)
1083+
1084+
# json using BUR
1085+
factory = get_factory('localhost', config={'splitFile': 'filename.json'})
10731086
exception_raised = False
10741087
try:
10751088
factory.block_until_ready(1)
1076-
except TimeoutException as e:
1089+
except Exception as e:
10771090
exception_raised = True
10781091

10791092
assert(exception_raised)
@@ -1082,6 +1095,7 @@ def test_incorrect_file_e2e(self):
10821095
factory.destroy(event)
10831096
event.wait()
10841097

1098+
10851099
def test_localhost_e2e(self):
10861100
"""Instantiate a client with a YAML file and issue get_treatment() calls."""
10871101
filename = os.path.join(os.path.dirname(__file__), 'files', 'file2.yaml')

0 commit comments

Comments
 (0)