Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Dec 12, 2024
1 parent 0b819fa commit 2c26718
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
11 changes: 9 additions & 2 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

client = TestClient(app)


def test_index():
response = client.get("/")
assert response.status_code == 200
Expand All @@ -33,11 +34,15 @@ async def test_returns_201_when_node_sync_is_acceptable():
"eth_height_remaining": 500,
}


@pytest.mark.asyncio
async def test_returns_503_when_node_sync_is_not_acceptable():
async_mock = AsyncMock()
async_mock.return_value = ScoringNodeSyncStatus(
acceptable=False, pending_messages=100, pending_txs=10, eth_height_remaining=2000
acceptable=False,
pending_messages=100,
pending_txs=10,
eth_height_remaining=2000,
)

with patch("monitoring_proxy.main.get_node_sync_status", new=async_mock):
Expand All @@ -51,6 +56,7 @@ async def test_returns_503_when_node_sync_is_not_acceptable():
"eth_height_remaining": 2000,
}


@pytest.mark.asyncio
async def test_returns_201_when_metrics_age_is_acceptable():
async_mock = AsyncMock()
Expand All @@ -68,6 +74,7 @@ async def test_returns_201_when_metrics_age_is_acceptable():
"reference_node": 3000,
}


@pytest.mark.asyncio
async def test_returns_503_when_metrics_age_is_not_acceptable():
async_mock = AsyncMock()
Expand All @@ -83,4 +90,4 @@ async def test_returns_503_when_metrics_age_is_not_acceptable():
"acceptable": False,
"scoring_node": 6000,
"reference_node": 6000,
}
}
26 changes: 15 additions & 11 deletions tests/test_scoring.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
from unittest.mock import patch, AsyncMock
from unittest.mock import AsyncMock, patch

import pytest
from aiohttp.client_exceptions import ClientError
from aioresponses import aioresponses

from monitoring_proxy.scoring import get_node_sync_status, get_scoring_node_metrics, parse_prometheus_metrics
from monitoring_proxy.scoring import (
get_node_sync_status,
get_scoring_node_metrics,
parse_prometheus_metrics,
)

NODE_METRICS = "\n".join(
(
"pyaleph_status_sync_pending_messages_total 10",
"pyaleph_status_sync_pending_txs_total 2",
"pyaleph_status_chain_eth_height_remaining_total 500",
)
)

NODE_METRICS = "\n".join((
"pyaleph_status_sync_pending_messages_total 10",
"pyaleph_status_sync_pending_txs_total 2",
"pyaleph_status_chain_eth_height_remaining_total 500",
))

@pytest.mark.asyncio
async def test_parse_prometheus_metrics():
Expand All @@ -25,10 +32,7 @@ async def test_parse_prometheus_metrics():
@pytest.mark.asyncio
async def test_returns_scoring_node_metrics():
with aioresponses() as mock_responses:
mock_responses.get(
"http://51.159.106.166:4024/metrics",
body=NODE_METRICS
)
mock_responses.get("http://51.159.106.166:4024/metrics", body=NODE_METRICS)

metrics = await get_scoring_node_metrics()
assert metrics["pyaleph_status_sync_pending_messages_total"] == 10
Expand Down

0 comments on commit 2c26718

Please sign in to comment.