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, "
@@ -956,15 +955,15 @@ def test_clear_manifest_cache() -> None:
956955 _manifests (io , list_path )
957956
958957 # Verify cache has entries
959- cache = _get_manifest_cache ()
958+ cache = manifest_module . _manifest_cache
960959 assert cache is not None , "Cache should be enabled"
961960 assert len (cache ) > 0 , "Cache should have entries after reading manifests"
962961
963962 # Clear the cache
964963 clear_manifest_cache ()
965964
966965 # Verify cache is empty but still enabled
967- cache_after = _get_manifest_cache ()
966+ cache_after = manifest_module . _manifest_cache
968967 assert cache_after is not None , "Cache should still be enabled after clear"
969968 assert len (cache_after ) == 0 , "Cache should be empty after clear"
970969
@@ -973,22 +972,19 @@ def test_clear_manifest_cache() -> None:
973972 "env_vars,expected_enabled,expected_size" ,
974973 [
975974 ({}, True , 128 ), # defaults
976- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "true" }, True , 128 ),
977- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "false" }, False , 128 ),
978- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "64" }, True , 64 ),
979- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "256" }, True , 256 ),
980- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "false" , "PYICEBERG_MANIFEST__CACHE__SIZE" : "64" }, False , 64 ),
975+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "64" }, True , 64 ),
976+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "256" }, True , 256 ),
977+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "0" }, False , 0 ), # size=0 disables cache
981978 ],
982979)
983980def test_manifest_cache_config_valid_values (env_vars : dict [str , str ], expected_enabled : bool , expected_size : int ) -> None :
984981 """Test that valid config values are applied correctly."""
985982 import os
986983
987984 with mock .patch .dict (os .environ , env_vars , clear = False ):
988- # Reset cache state so config is re-read
989- manifest_module ._manifest_cache_manager ._cache = None
990- manifest_module ._manifest_cache_manager ._initialized = False
991- cache = _get_manifest_cache ()
985+ with manifest_module ._manifest_cache_lock :
986+ manifest_module ._manifest_cache = manifest_module ._init_manifest_cache ()
987+ cache = manifest_module ._manifest_cache
992988
993989 if expected_enabled :
994990 assert cache is not None , "Cache should be enabled"
@@ -1000,20 +996,15 @@ def test_manifest_cache_config_valid_values(env_vars: dict[str, str], expected_e
1000996@pytest .mark .parametrize (
1001997 "env_vars,expected_error_substring" ,
1002998 [
1003- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "maybe" }, "manifest.cache.enabled should be a boolean" ),
1004- ({"PYICEBERG_MANIFEST__CACHE__ENABLED" : "invalid" }, "manifest.cache.enabled should be a boolean" ),
1005- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "abc" }, "manifest.cache.size should be a positive integer" ),
1006- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "0" }, "manifest.cache.size must be >= 1" ),
1007- ({"PYICEBERG_MANIFEST__CACHE__SIZE" : "-5" }, "manifest.cache.size must be >= 1" ),
999+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "abc" }, "manifest-cache-size should be an integer" ),
1000+ ({"PYICEBERG_MANIFEST_CACHE_SIZE" : "-5" }, "manifest-cache-size must be >= 0" ),
10081001 ],
10091002)
10101003def test_manifest_cache_config_invalid_values (env_vars : dict [str , str ], expected_error_substring : str ) -> None :
10111004 """Test that invalid config values raise ValueError with appropriate message."""
10121005 import os
10131006
10141007 with mock .patch .dict (os .environ , env_vars , clear = False ):
1015- # Reset cache state so config is re-read
1016- manifest_module ._manifest_cache_manager ._cache = None
1017- manifest_module ._manifest_cache_manager ._initialized = False
10181008 with pytest .raises (ValueError , match = expected_error_substring ):
1019- _get_manifest_cache ()
1009+ with manifest_module ._manifest_cache_lock :
1010+ manifest_module ._manifest_cache = manifest_module ._init_manifest_cache ()
0 commit comments