Skip to content

Conversation

@joker23
Copy link
Contributor

@joker23 joker23 commented Nov 25, 2025

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

This PR will:

  1. add the file data source to the custom fdv2 datasystem configuration
  2. modify the initialization logic so it aligns with spec. Namely, we will continue through the initializer list until we either run out of intializers (in which case the synchronizers will try to do a valid initialization) OR if an intializer fetched a proper basis with a selector.

Note

Introduces a file-based initializer and updates FDv2 to mark ready only when an initializer provides a selector, with tests validating initializer ordering and early completion.

  • Core:
    • Add file_ds_builder(paths) returning _FileDataSourceV2 initializer in ldclient/datasystem.py; import _FileDataSourceV2.
  • FDv2 Initialization Logic (ldclient/impl/datasystem/fdv2.py):
    • After applying an initializer basis, set ready only if basis.change_set.selector is defined; then return to proceed to synchronizers.
  • Tests (ldclient/testing/impl/datasystem/test_fdv2_datasystem.py):
    • Add tests ensuring initializers run until first success and stop on first initializer that provides a selector; verify transition to synchronizers.
    • Include file-based data source usage via file_ds_builder with temp JSON files.

Written by Cursor Bugbot for commit 04a2c53. This will update automatically on new commits. Configure here.

@joker23 joker23 requested a review from a team as a code owner November 25, 2025 18:07
This commit will make it so that the client will only report initalized when a valid selector is present in the basis
@joker23 joker23 force-pushed the skz/sdk-1641/implement-intializer-specs branch from 570b033 to 064f65c Compare November 25, 2025 18:13
assert flag is not None


def test_fdv2_with_file_to_polling_initializers():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests reference polling, but they are using the test data sources instead. So we should probably update the language.

Comment on lines 488 to 489
assert set_on_ready.wait(1), "Data system did not become ready in time"
assert count == 2, "Invalid initializer process"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure there isn't a timing issue in this test? You are testing for 2 callbacks, but it may actually do 3 -- one for each initialization, and then another when the sync runs the first time.

Copy link
Contributor Author

@joker23 joker23 Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I think I misunderstood these test datasource... I thought that the test datasources will only give a response/trigger a callback if we call the update function? eg https://github.com/launchdarkly/python-server-sdk/pull/381/files/064f65c76135c385a6fdcb0209caa0e7a8cf872c#diff-1cee15fc62f5439ab90479c81c5cf48672134012d9b81254303605674e9c4fb4R467 ...if not then what would be a good way to test this? just wait for the synchronizer to finish and make it count 3?

UPDATE: yea I played around a bit more and there is a race condition and I think these tests pass because I immediately close the client after the ready event. Will change.

fdv2.flag_tracker.add_listener(listener)

fdv2.start(set_on_ready)
assert set_on_ready.wait(1), "Data system did not become ready in time"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here. Is it possible the change handler could run twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So assuming that we don't count the synchronizer, the change handler should only run once as the file data source will be skipped in this instance so if the change handler runs more than once during the initialization phase then it is a problem.

- 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
@joker23
Copy link
Contributor Author

joker23 commented Nov 25, 2025

@keelerm84 I changed up the tests a bit and I think they shouldn't run into race conditions anymore

@joker23 joker23 requested a review from keelerm84 November 25, 2025 23:49
@joker23 joker23 merged commit 3700d1d into main Nov 26, 2025
15 checks passed
@joker23 joker23 deleted the skz/sdk-1641/implement-intializer-specs branch November 26, 2025 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants