-
Notifications
You must be signed in to change notification settings - Fork 44
fix: Fix data and target availability for daemon mode #385
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
Draft
keelerm84
wants to merge
1
commit into
main
Choose a base branch
from
mk/sdk-1654/fix-availability
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+238
−4
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
ldclient/testing/impl/datasystem/test_fdv1_availability.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # pylint: disable=missing-docstring | ||
|
|
||
| from threading import Event | ||
|
|
||
| from ldclient.config import Config | ||
| from ldclient.feature_store import InMemoryFeatureStore | ||
| from ldclient.impl.datasystem import DataAvailability | ||
| from ldclient.impl.datasystem.fdv1 import FDv1 | ||
| from ldclient.versioned_data_kind import FEATURES | ||
|
|
||
|
|
||
| def test_fdv1_availability_offline(): | ||
| """Test that FDv1 returns DEFAULTS for both data and target availability when offline.""" | ||
| config = Config(sdk_key="sdk-key", offline=True) | ||
| fdv1 = FDv1(config) | ||
|
|
||
| assert fdv1.data_availability == DataAvailability.DEFAULTS | ||
| assert fdv1.target_availability == DataAvailability.DEFAULTS | ||
|
|
||
|
|
||
| def test_fdv1_availability_ldd_mode_uninitialized(): | ||
| """Test that FDv1 returns DEFAULTS for data and CACHED for target when LDD mode with uninitialized store.""" | ||
| store = InMemoryFeatureStore() | ||
| config = Config(sdk_key="sdk-key", use_ldd=True, feature_store=store) | ||
| fdv1 = FDv1(config) | ||
|
|
||
| # Store is not initialized yet | ||
| assert not store.initialized | ||
| assert fdv1.data_availability == DataAvailability.DEFAULTS | ||
| assert fdv1.target_availability == DataAvailability.CACHED | ||
|
|
||
|
|
||
| def test_fdv1_availability_ldd_mode_initialized(): | ||
| """Test that FDv1 returns CACHED for both when LDD mode with initialized store.""" | ||
| store = InMemoryFeatureStore() | ||
| config = Config(sdk_key="sdk-key", use_ldd=True, feature_store=store) | ||
| fdv1 = FDv1(config) | ||
|
|
||
| # Initialize the store | ||
| store.init({FEATURES: {}}) | ||
|
|
||
| assert store.initialized | ||
| assert fdv1.data_availability == DataAvailability.CACHED | ||
| assert fdv1.target_availability == DataAvailability.CACHED | ||
|
|
||
|
|
||
| def test_fdv1_availability_normal_mode_uninitialized(): | ||
| """Test that FDv1 returns DEFAULTS for data and REFRESHED for target in normal mode when not initialized.""" | ||
| store = InMemoryFeatureStore() | ||
| config = Config(sdk_key="sdk-key", feature_store=store) | ||
| fdv1 = FDv1(config) | ||
|
|
||
| # Update processor not started, store not initialized | ||
| assert fdv1.data_availability == DataAvailability.DEFAULTS | ||
| assert fdv1.target_availability == DataAvailability.REFRESHED | ||
|
|
||
|
|
||
| def test_fdv1_availability_normal_mode_store_initialized(): | ||
| """Test that FDv1 returns CACHED for data and REFRESHED for target when store is initialized but update processor is not.""" | ||
| store = InMemoryFeatureStore() | ||
| config = Config(sdk_key="sdk-key", feature_store=store) | ||
| fdv1 = FDv1(config) | ||
|
|
||
| # Initialize store but don't start update processor | ||
| fdv1._store_wrapper.init({FEATURES: {}}) | ||
|
|
||
| assert fdv1.data_availability == DataAvailability.CACHED | ||
| assert fdv1.target_availability == DataAvailability.REFRESHED |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Missing offline check in FDv2 data_availability property
The
data_availabilityproperty in FDv2 is missing an offline check, unliketarget_availabilitywhich explicitly checksself._config.offlineand returnsDEFAULTS. In FDv1, both properties check for offline mode first. Without this check, if the store happens to be initialized while in offline mode,data_availabilitywould returnCACHEDinstead ofDEFAULTS, creating inconsistent behavior between the two availability properties and between FDv1 and FDv2.