fix: resolve flaky test and JSON config validation
This commit is contained in:
@@ -217,14 +217,14 @@ class ConfigLoader:
|
|||||||
|
|
||||||
return env_vars
|
return env_vars
|
||||||
|
|
||||||
def _load_json_file(self, file_path: Path) -> dict[str, Any]:
|
def _load_json_file(self, file_path: Path) -> Any:
|
||||||
"""Load configuration from a JSON file.
|
"""Load configuration from a JSON file.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
file_path: Path to the JSON file.
|
file_path: Path to the JSON file.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Configuration dictionary.
|
Parsed JSON data (could be any JSON type).
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ConfigurationError: If the file cannot be read or parsed.
|
ConfigurationError: If the file cannot be read or parsed.
|
||||||
@@ -235,7 +235,7 @@ class ConfigLoader:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
with file_path.open(encoding="utf-8") as f:
|
with file_path.open(encoding="utf-8") as f:
|
||||||
data: dict[str, Any] = json.load(f)
|
data: Any = json.load(f)
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
msg = f"Invalid JSON in {file_path}: {e}"
|
msg = f"Invalid JSON in {file_path}: {e}"
|
||||||
raise ConfigurationError(msg) from e
|
raise ConfigurationError(msg) from e
|
||||||
@@ -350,6 +350,9 @@ class ConfigLoader:
|
|||||||
"""
|
"""
|
||||||
path = Path(file_path)
|
path = Path(file_path)
|
||||||
raw_config = self._load_json_file(path)
|
raw_config = self._load_json_file(path)
|
||||||
|
if not isinstance(raw_config, dict):
|
||||||
|
msg = "JSON root must be an object"
|
||||||
|
raise ConfigurationError(msg)
|
||||||
config_dict = self._validate_and_convert(raw_config, _RATE_LIMIT_FIELD_TYPES)
|
config_dict = self._validate_and_convert(raw_config, _RATE_LIMIT_FIELD_TYPES)
|
||||||
|
|
||||||
# Apply overrides
|
# Apply overrides
|
||||||
|
|||||||
@@ -426,7 +426,8 @@ class TestSlidingWindowCounterAdvanced:
|
|||||||
allowed, _ = await algo.check("precision_key")
|
allowed, _ = await algo.check("precision_key")
|
||||||
assert not allowed
|
assert not allowed
|
||||||
|
|
||||||
await asyncio.sleep(0.5)
|
# Wait for the full window to pass to ensure tokens are fully replenished
|
||||||
|
await asyncio.sleep(1.1)
|
||||||
|
|
||||||
allowed, _ = await algo.check("precision_key")
|
allowed, _ = await algo.check("precision_key")
|
||||||
assert allowed
|
assert allowed
|
||||||
|
|||||||
Reference in New Issue
Block a user