Skip to content

Commit 76978a7

Browse files
committed
docstrings and doctests
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
1 parent 6a6ccfc commit 76978a7

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

mcpgateway/services/gateway_service.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,22 @@ async def check_health_of_gateways(self, db: Session, gateways: List[DbGateway],
21452145
semaphore = asyncio.Semaphore(concurrency_limit)
21462146

21472147
async def limited_check(gateway: DbGateway):
2148+
"""
2149+
Checks the health of a single gateway while respecting a concurrency limit.
2150+
2151+
This function checks the health of the given database gateway, ensuring that
2152+
the number of concurrent checks does not exceed a predefined limit. The check
2153+
is performed asynchronously and uses a semaphore to manage concurrency.
2154+
2155+
Args:
2156+
gateway (DbGateway): The database gateway whose health is to be checked.
2157+
2158+
Returns:
2159+
None: This function performs an action (checking health) but does not return any value.
2160+
2161+
Raises:
2162+
Any exceptions raised during the health check will be propagated to the caller.
2163+
"""
21482164
async with semaphore:
21492165
await self._check_single_gateway_health(db, gateway, user_email)
21502166

mcpgateway/services/server_service.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,16 @@ async def aggregate_metrics(self, db: Session) -> ServerMetrics:
12291229
>>> from unittest.mock import MagicMock
12301230
>>> service = ServerService()
12311231
>>> db = MagicMock()
1232-
>>> db.execute.return_value.scalar.return_value = 0
1232+
>>> # Mocking the result to return values that can be compared with integers
1233+
>>> db.execute.return_value.one.return_value = MagicMock(
1234+
... total_executions=10,
1235+
... successful_executions=8,
1236+
... failed_executions=2,
1237+
... min_response_time=0.1,
1238+
... max_response_time=0.5,
1239+
... avg_response_time=0.3,
1240+
... last_execution_time="2023-12-01T12:00:00"
1241+
... )
12331242
>>> import asyncio
12341243
>>> result = asyncio.run(service.aggregate_metrics(db))
12351244
>>> hasattr(result, 'total_executions')

0 commit comments

Comments
 (0)