Skip to content

Commit 04a2c53

Browse files
committed
chore: PR comments
- modified the tests to be more robust - modified wording on test to be more clear on what is being tested - removed unnecessary check for ready event
1 parent 064f65c commit 04a2c53

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

ldclient/impl/datasystem/fdv2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,7 @@ def _run_initializers(self, set_on_ready: Event):
410410
self._store.apply(basis.change_set, basis.persist)
411411

412412
# Set ready event if an only if a selector is defined for the changeset
413-
selector_is_defined = basis.change_set.selector is not None and basis.change_set.selector.is_defined()
414-
if selector_is_defined and not set_on_ready.is_set():
413+
if basis.change_set.selector is not None and basis.change_set.selector.is_defined():
415414
set_on_ready.set()
416415
return
417416
except Exception as e:

ldclient/testing/impl/datasystem/test_fdv2_datasystem.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,10 @@ def test_fdv2_stays_on_fdv1_after_fallback():
437437
assert flag is not None
438438

439439

440-
def test_fdv2_with_file_to_polling_initializers():
440+
def test_fdv2_initializer_should_run_until_success():
441441
"""
442-
Test that FDv2 can be initialized with a file data source and a polling data source.
443-
In this case the results from the file data source should be overwritten by the
444-
results from the polling datasource.
442+
Test that FDv2 initializers will run in order until a successful run. Then
443+
the datasystem is expected to transition to run synchronizers.
445444
"""
446445
initial_flag_data = '''
447446
{
@@ -475,27 +474,29 @@ def test_fdv2_with_file_to_polling_initializers():
475474
)
476475

477476
set_on_ready = Event()
477+
synchronizer_ran = Event()
478478
fdv2 = FDv2(Config(sdk_key="dummy"), data_system_config)
479479
count = 0
480480

481481
def listener(_: FlagChange):
482482
nonlocal count
483483
count += 1
484+
if count == 3:
485+
synchronizer_ran.set()
484486

485487
fdv2.flag_tracker.add_listener(listener)
486488

487489
fdv2.start(set_on_ready)
488490
assert set_on_ready.wait(1), "Data system did not become ready in time"
489-
assert count == 2, "Invalid initializer process"
490-
fdv2.stop()
491+
assert synchronizer_ran.wait(1), "Data system did not transition to synchronizer"
491492
finally:
492493
os.remove(path)
493494

494495

495-
def test_fdv2_with_polling_to_file_initializers():
496+
def test_fdv2_should_finish_initialization_on_first_successful_initializer():
496497
"""
497-
Test that when FDv2 is initialized with a polling datasource and a file datasource
498-
then only the polling processor needs to run.
498+
Test that when a FDv2 initializer returns a basis and selector that the rest
499+
of the intializers will be skipped and the client starts synchronizing phase.
499500
"""
500501
initial_flag_data = '''
501502
{
@@ -525,7 +526,7 @@ def test_fdv2_with_polling_to_file_initializers():
525526

526527
data_system_config = DataSystemConfig(
527528
initializers=[td_initializer.build_initializer, file_ds_builder([path])],
528-
primary_synchronizer=td_synchronizer.build_synchronizer,
529+
primary_synchronizer=None,
529530
)
530531

531532
set_on_ready = Event()

0 commit comments

Comments
 (0)