5252
5353@pytest .fixture (autouse = True )
5454def reset_global_manifests_cache () -> None :
55- # Reset cache state before each test so config is re-read
56- manifest_module ._manifest_cache_manager . _cache = None
57- manifest_module . _manifest_cache_manager . _initialized = False
55+ with manifest_module . _manifest_cache_lock :
56+ manifest_module ._manifest_cache = manifest_module . _init_manifest_cache ()
57+ clear_manifest_cache ()
5858
5959
6060def _verify_metadata_with_fastavro (avro_file : str , expected_metadata : dict [str , str ]) -> None :
@@ -810,7 +810,7 @@ def test_manifest_cache_deduplicates_manifest_files() -> None:
810810
811811 # Verify cache size - should only have 3 unique ManifestFile objects
812812 # instead of 1 + 2 + 3 = 6 objects as with the old approach
813- cache = _get_manifest_cache ()
813+ cache = manifest_module . _manifest_cache
814814 assert cache is not None , "Manifest cache should be enabled for this test"
815815 assert len (cache ) == 3 , f"Cache should contain exactly 3 unique ManifestFile objects, but has { len (cache )} "
816816
@@ -885,7 +885,7 @@ def test_manifest_cache_efficiency_with_many_overlapping_lists() -> None:
885885 # With the new approach, we should have exactly N objects
886886
887887 # Verify cache has exactly N unique entries
888- cache = _get_manifest_cache ()
888+ cache = manifest_module . _manifest_cache
889889 assert cache is not None , "Manifest cache should be enabled for this test"
890890 assert len (cache ) == num_manifests , (
891891 f"Cache should contain exactly { num_manifests } ManifestFile objects, "
@@ -1031,15 +1031,15 @@ def test_clear_manifest_cache() -> None:
10311031 _manifests (io , list_path )
10321032
10331033 # Verify cache has entries
1034- cache = _get_manifest_cache ()
1034+ cache = manifest_module . _manifest_cache
10351035 assert cache is not None , "Cache should be enabled"
10361036 assert len (cache ) > 0 , "Cache should have entries after reading manifests"
10371037
10381038 # Clear the cache
10391039 clear_manifest_cache ()
10401040
10411041 # Verify cache is empty but still enabled
1042- cache_after = _get_manifest_cache ()
1042+ cache_after = manifest_module . _manifest_cache
10431043 assert cache_after is not None , "Cache should still be enabled after clear"
10441044 assert len (cache_after ) == 0 , "Cache should be empty after clear"
10451045
@@ -1048,22 +1048,19 @@ def test_clear_manifest_cache() -> None:
10481048 "env_vars,expected_enabled,expected_size" ,
10491049 [
10501050 ({}, True , 128 ), # defaults
1051- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "true" }, True , 128 ),
1052- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "false" }, False , 128 ),
1053- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "64" }, True , 64 ),
1054- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "256" }, True , 256 ),
1055- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "false" , "PYICEBERG_MANIFEST__CACHE__SIZE" : "64" }, False , 64 ),
1051+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "64" }, True , 64 ),
1052+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "256" }, True , 256 ),
1053+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "0" }, False , 0 ), # size=0 disables cache
10561054 ],
10571055)
10581056def test_manifest_cache_config_valid_values (env_vars : dict [str , str ], expected_enabled : bool , expected_size : int ) -> None :
10591057 """Test that valid config values are applied correctly."""
10601058 import os
10611059
10621060 with mock .patch .dict (os .environ , env_vars , clear = False ):
1063- # Reset cache state so config is re-read
1064- manifest_module ._manifest_cache_manager ._cache = None
1065- manifest_module ._manifest_cache_manager ._initialized = False
1066- cache = _get_manifest_cache ()
1061+ with manifest_module ._manifest_cache_lock :
1062+ manifest_module ._manifest_cache = manifest_module ._init_manifest_cache ()
1063+ cache = manifest_module ._manifest_cache
10671064
10681065 if expected_enabled :
10691066 assert cache is not None , "Cache should be enabled"
@@ -1075,20 +1072,15 @@ def test_manifest_cache_config_valid_values(env_vars: dict[str, str], expected_e
10751072@pytest .mark .parametrize (
10761073 "env_vars,expected_error_substring" ,
10771074 [
1078- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "maybe" }, "manifest.cache.enabled should be a boolean" ),
1079- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "invalid" }, "manifest.cache.enabled should be a boolean" ),
1080- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "abc" }, "manifest.cache.size should be a positive integer" ),
1081- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "0" }, "manifest.cache.size must be >= 1" ),
1082- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "-5" }, "manifest.cache.size must be >= 1" ),
1075+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "abc" }, "manifest-cache-size should be an integer" ),
1076+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "-5" }, "manifest-cache-size must be >= 0" ),
10831077 ],
10841078)
10851079def test_manifest_cache_config_invalid_values (env_vars : dict [str , str ], expected_error_substring : str ) -> None :
10861080 """Test that invalid config values raise ValueError with appropriate message."""
10871081 import os
10881082
10891083 with mock .patch .dict (os .environ , env_vars , clear = False ):
1090- # Reset cache state so config is re-read
1091- manifest_module ._manifest_cache_manager ._cache = None
1092- manifest_module ._manifest_cache_manager ._initialized = False
10931084 with pytest .raises (ValueError , match = expected_error_substring ):
1094- _get_manifest_cache ()
1085+ with manifest_module ._manifest_cache_lock :
1086+ manifest_module ._manifest_cache = manifest_module ._init_manifest_cache ()
0 commit comments