Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Dec 12, 2024
1 parent 2c26718 commit 746c055
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/monitoring_proxy/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ async def get_recent_metrics_age(api_url_prefix: str, now: datetime) -> timedelt
Get the age of the most recent metrics from the specified `pyaleph` node.
"""
recent_metrics = await get_recent_metrics(api_url_prefix)
print(recent_metrics)
signed_timestamp: float = recent_metrics[0]["content"]["time"]
signed_datetime = datetime.fromtimestamp(signed_timestamp, tz=timezone.utc)
print("Z", now, signed_datetime, recent_metrics[0]["content"]["time"])
return now - signed_datetime


Expand Down
11 changes: 9 additions & 2 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime, timedelta, timezone
from unittest.mock import AsyncMock, patch
from unittest.mock import AsyncMock, MagicMock, patch

import pytest
from aioresponses import aioresponses
Expand Down Expand Up @@ -74,8 +74,15 @@ async def test_returns_metrics_age_by_node():
{"content": {"time": (now - timedelta(minutes=30)).timestamp()}}
]

def mock_now(tz=None):
return now

mock_datetime = MagicMock(now=mock_now)
mock_datetime.fromtimestamp = datetime.fromtimestamp

with patch("monitoring_proxy.metrics.get_recent_metrics", new=async_mock):
metrics_age = await get_metrics_age_by_node()
with patch("monitoring_proxy.metrics.datetime", new=mock_datetime):
metrics_age = await get_metrics_age_by_node()

assert metrics_age.acceptable
assert metrics_age.scoring_node < 5400
Expand Down

0 comments on commit 746c055

Please sign in to comment.