|
1 | 1 | from datetime import datetime, timedelta |
2 | 2 | from tempfile import mkstemp |
| 3 | +from unittest.mock import patch |
3 | 4 |
|
4 | 5 | import pytest |
5 | 6 | from pytest_lazyfixture import lazy_fixture |
|
18 | 19 | from feast.permissions.action import AuthzedAction |
19 | 20 | from feast.permissions.permission import Permission |
20 | 21 | from feast.permissions.policy import RoleBasedPolicy |
21 | | -from feast.repo_config import RepoConfig |
| 22 | +from feast.repo_config import RegistryConfig, RepoConfig |
22 | 23 | from feast.stream_feature_view import stream_feature_view |
23 | 24 | from feast.types import Array, Bytes, Float32, Int64, String, ValueType, from_value_type |
24 | 25 | from tests.integration.feature_repos.universal.feature_views import TAGS |
@@ -797,3 +798,67 @@ def feature_store_with_local_registry(): |
797 | 798 | entity_key_serialization_version=3, |
798 | 799 | ) |
799 | 800 | ) |
| 801 | + |
| 802 | + |
| 803 | +@pytest.mark.parametrize( |
| 804 | + "test_feature_store", |
| 805 | + [lazy_fixture("feature_store_with_local_registry")], |
| 806 | +) |
| 807 | +def test_apply_refreshes_registry_cache_sync_mode(test_feature_store): |
| 808 | + """Test that apply() refreshes registry cache when cache_mode is 'sync' (default)""" |
| 809 | + # Create a simple entity (no FeatureView to avoid file path issues) |
| 810 | + entity = Entity(name="test_entity", join_keys=["id"]) |
| 811 | + |
| 812 | + # Mock the refresh_registry method to verify it's called |
| 813 | + with patch.object(test_feature_store, "refresh_registry") as mock_refresh: |
| 814 | + # Apply the entity |
| 815 | + test_feature_store.apply([entity]) |
| 816 | + |
| 817 | + # Verify refresh_registry was called once (due to sync mode) |
| 818 | + mock_refresh.assert_called_once() |
| 819 | + |
| 820 | + test_feature_store.teardown() |
| 821 | + |
| 822 | + |
| 823 | +@pytest.mark.parametrize( |
| 824 | + "test_feature_store", |
| 825 | + [lazy_fixture("feature_store_with_local_registry")], |
| 826 | +) |
| 827 | +def test_apply_skips_refresh_registry_cache_thread_mode(test_feature_store): |
| 828 | + """Test that apply() skips registry refresh when cache_mode is 'thread'""" |
| 829 | + # Create a simple entity |
| 830 | + entity = Entity(name="test_entity", join_keys=["id"]) |
| 831 | + |
| 832 | + # Temporarily change cache_mode to 'thread' |
| 833 | + original_cache_mode = test_feature_store.config.registry.cache_mode |
| 834 | + test_feature_store.config.registry.cache_mode = "thread" |
| 835 | + |
| 836 | + try: |
| 837 | + # Mock the refresh_registry method to verify it's NOT called |
| 838 | + with patch.object(test_feature_store, "refresh_registry") as mock_refresh: |
| 839 | + # Apply the entity |
| 840 | + test_feature_store.apply([entity]) |
| 841 | + |
| 842 | + # Verify refresh_registry was NOT called (due to thread mode) |
| 843 | + mock_refresh.assert_not_called() |
| 844 | + finally: |
| 845 | + # Restore original cache_mode |
| 846 | + test_feature_store.config.registry.cache_mode = original_cache_mode |
| 847 | + |
| 848 | + test_feature_store.teardown() |
| 849 | + |
| 850 | + |
| 851 | +def test_registry_config_cache_mode_default(): |
| 852 | + """Test that RegistryConfig has cache_mode with default value 'sync'""" |
| 853 | + config = RegistryConfig() |
| 854 | + assert hasattr(config, "cache_mode") |
| 855 | + assert config.cache_mode == "sync" |
| 856 | + |
| 857 | + |
| 858 | +def test_registry_config_cache_mode_can_be_set(): |
| 859 | + """Test that RegistryConfig cache_mode can be set to different values""" |
| 860 | + config = RegistryConfig(cache_mode="thread") |
| 861 | + assert config.cache_mode == "thread" |
| 862 | + |
| 863 | + config = RegistryConfig(cache_mode="sync") |
| 864 | + assert config.cache_mode == "sync" |
0 commit comments