Skip to content
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
10 changes: 4 additions & 6 deletions splitio/client/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,12 @@ def __init__( # pylint: disable=too-many-arguments
if self._sdk_ready_flag is not None:
self._status = Status.NOT_INITIALIZED
# add a listener that updates the status to READY once the flag is set.
ready_updater = threading.Thread(target=self._update_status_when_ready)
ready_updater = threading.Thread(target=self.block_until_ready)
ready_updater.setDaemon(True)
ready_updater.start()
else:
self._status = Status.READY

def _update_status_when_ready(self):
"""Wait until the sdk is ready and update the status."""
self._sdk_ready_flag.wait()
self._status = Status.READY

def _get_storage(self, name):
"""
Return a reference to the specified storage.
Expand Down Expand Up @@ -152,6 +147,7 @@ def manager(self):
def block_until_ready(self, timeout=None):
"""
Blocks until the sdk is ready or the timeout specified by the user expires.
When ready, the factory's status is updated accordingly.

:param timeout: Number of seconds to wait (fractions allowed)
:type timeout: int
Expand All @@ -162,6 +158,8 @@ def block_until_ready(self, timeout=None):
if not ready:
raise TimeoutException('SDK Initialization: time of %d exceeded' % timeout)

self._status = Status.READY

@property
def ready(self):
"""
Expand Down
5 changes: 0 additions & 5 deletions tests/client/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def _segment_task_init_mock(self, api, storage, split_storage, period, event):
assert factory._tasks['telemetry']._api == factory._apis['telemetry']
assert factory._labels_enabled is True
factory.block_until_ready()
time.sleep(1) # give a chance for the bg thread to set the ready status
assert factory.ready
factory.destroy()

Expand Down Expand Up @@ -164,7 +163,6 @@ def test_redis_client_creation(self, mocker):
assert factory._labels_enabled is False
assert isinstance(factory._impression_listener, ImpressionListenerWrapper)
factory.block_until_ready()
time.sleep(1) # give a chance for the bg thread to set the ready status
assert factory.ready
factory.destroy()

Expand All @@ -182,7 +180,6 @@ def test_uwsgi_client_creation(self):
assert factory._labels_enabled is True
assert factory._impression_listener is None
factory.block_until_ready()
time.sleep(1) # give a chance for the bg thread to set the ready status
assert factory.ready
factory.destroy()

Expand Down Expand Up @@ -233,7 +230,6 @@ def _event_task_init_mock(self, api, storage, refresh_rate, bulk_size):
# Start factory and make assertions
factory = get_factory('some_api_key')
factory.block_until_ready()
time.sleep(1) # give a chance for the bg thread to set the ready status
assert factory.ready
assert factory.destroyed is False

Expand Down Expand Up @@ -303,7 +299,6 @@ def _telemetry_task_init_mock(self, api, storage, refresh_rate):
assert factory.destroyed is False

factory.block_until_ready()
time.sleep(1) # give a chance for the bg thread to set the ready status
assert factory.ready

event = threading.Event()
Expand Down
1 change: 0 additions & 1 deletion tests/integration/test_client_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,6 @@ def test_localhost_e2e(self):
filename = os.path.join(os.path.dirname(__file__), 'files', 'file2.yaml')
factory = get_factory('localhost', config={'splitFile': filename})
factory.block_until_ready()
time.sleep(1)
client = factory.client()
assert client.get_treatment_with_config('key', 'my_feature') == ('on', '{"desc" : "this applies only to ON treatment"}')
assert client.get_treatment_with_config('only_key', 'my_feature') == (
Expand Down