3434 ManifestEntryStatus ,
3535 ManifestFile ,
3636 PartitionFieldSummary ,
37- _get_manifest_cache ,
3837 _manifests ,
3938 clear_manifest_cache ,
4039 read_manifest_list ,
5049
5150@pytest .fixture (autouse = True )
5251def reset_global_manifests_cache () -> None :
53- # Reset cache state before each test so config is re-read
54- manifest_module ._manifest_cache_manager . _cache = None
55- manifest_module . _manifest_cache_manager . _initialized = False
52+ with manifest_module . _manifest_cache_lock :
53+ manifest_module ._manifest_cache = manifest_module . _init_manifest_cache ()
54+ clear_manifest_cache ()
5655
5756
5857def _verify_metadata_with_fastavro (avro_file : str , expected_metadata : dict [str , str ]) -> None :
@@ -808,7 +807,7 @@ def test_manifest_cache_deduplicates_manifest_files() -> None:
808807
809808 # Verify cache size - should only have 3 unique ManifestFile objects
810809 # instead of 1 + 2 + 3 = 6 objects as with the old approach
811- cache = _get_manifest_cache ()
810+ cache = manifest_module . _manifest_cache
812811 assert cache is not None , "Manifest cache should be enabled for this test"
813812 assert len (cache ) == 3 , f"Cache should contain exactly 3 unique ManifestFile objects, but has { len (cache )} "
814813
@@ -883,7 +882,7 @@ def test_manifest_cache_efficiency_with_many_overlapping_lists() -> None:
883882 # With the new approach, we should have exactly N objects
884883
885884 # Verify cache has exactly N unique entries
886- cache = _get_manifest_cache ()
885+ cache = manifest_module . _manifest_cache
887886 assert cache is not None , "Manifest cache should be enabled for this test"
888887 assert len (cache ) == num_manifests , (
889888 f"Cache should contain exactly { num_manifests } ManifestFile objects, "
@@ -991,15 +990,15 @@ def test_clear_manifest_cache() -> None:
991990 _manifests (io , list_path )
992991
993992 # Verify cache has entries
994- cache = _get_manifest_cache ()
993+ cache = manifest_module . _manifest_cache
995994 assert cache is not None , "Cache should be enabled"
996995 assert len (cache ) > 0 , "Cache should have entries after reading manifests"
997996
998997 # Clear the cache
999998 clear_manifest_cache ()
1000999
10011000 # Verify cache is empty but still enabled
1002- cache_after = _get_manifest_cache ()
1001+ cache_after = manifest_module . _manifest_cache
10031002 assert cache_after is not None , "Cache should still be enabled after clear"
10041003 assert len (cache_after ) == 0 , "Cache should be empty after clear"
10051004
@@ -1008,22 +1007,19 @@ def test_clear_manifest_cache() -> None:
10081007 "env_vars,expected_enabled,expected_size" ,
10091008 [
10101009 ({}, True , 128 ), # defaults
1011- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "true" }, True , 128 ),
1012- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "false" }, False , 128 ),
1013- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "64" }, True , 64 ),
1014- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "256" }, True , 256 ),
1015- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "false" , "PYICEBERG_MANIFEST__CACHE__SIZE" : "64" }, False , 64 ),
1010+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "64" }, True , 64 ),
1011+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "256" }, True , 256 ),
1012+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "0" }, False , 0 ), # size=0 disables cache
10161013 ],
10171014)
10181015def test_manifest_cache_config_valid_values (env_vars : dict [str , str ], expected_enabled : bool , expected_size : int ) -> None :
10191016 """Test that valid config values are applied correctly."""
10201017 import os
10211018
10221019 with mock .patch .dict (os .environ , env_vars , clear = False ):
1023- # Reset cache state so config is re-read
1024- manifest_module ._manifest_cache_manager ._cache = None
1025- manifest_module ._manifest_cache_manager ._initialized = False
1026- cache = _get_manifest_cache ()
1020+ with manifest_module ._manifest_cache_lock :
1021+ manifest_module ._manifest_cache = manifest_module ._init_manifest_cache ()
1022+ cache = manifest_module ._manifest_cache
10271023
10281024 if expected_enabled :
10291025 assert cache is not None , "Cache should be enabled"
@@ -1035,20 +1031,15 @@ def test_manifest_cache_config_valid_values(env_vars: dict[str, str], expected_e
10351031@pytest .mark .parametrize (
10361032 "env_vars,expected_error_substring" ,
10371033 [
1038- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "maybe" }, "manifest.cache.enabled should be a boolean" ),
1039- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "invalid" }, "manifest.cache.enabled should be a boolean" ),
1040- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "abc" }, "manifest.cache.size should be a positive integer" ),
1041- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "0" }, "manifest.cache.size must be >= 1" ),
1042- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "-5" }, "manifest.cache.size must be >= 1" ),
1034+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "abc" }, "manifest-cache-size should be an integer" ),
1035+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "-5" }, "manifest-cache-size must be >= 0" ),
10431036 ],
10441037)
10451038def test_manifest_cache_config_invalid_values (env_vars : dict [str , str ], expected_error_substring : str ) -> None :
10461039 """Test that invalid config values raise ValueError with appropriate message."""
10471040 import os
10481041
10491042 with mock .patch .dict (os .environ , env_vars , clear = False ):
1050- # Reset cache state so config is re-read
1051- manifest_module ._manifest_cache_manager ._cache = None
1052- manifest_module ._manifest_cache_manager ._initialized = False
10531043 with pytest .raises (ValueError , match = expected_error_substring ):
1054- _get_manifest_cache ()
1044+ with manifest_module ._manifest_cache_lock :
1045+ manifest_module ._manifest_cache = manifest_module ._init_manifest_cache ()
0 commit comments