mirror of
https://github.com/sortedcord/alemno-payments.git
synced 2026-07-22 04:02:49 +05:30
feat: Implemented observability layer and benchmarking
This commit is contained in:
53
tests/services/test_benchmarker.py
Normal file
53
tests/services/test_benchmarker.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import pytest
|
||||
import asyncio
|
||||
from app.core.observability import benchmark, time_it
|
||||
|
||||
|
||||
def test_benchmark_context_manager(caplog):
|
||||
import logging
|
||||
|
||||
with caplog.at_level(logging.INFO):
|
||||
with benchmark("Test Task"):
|
||||
# simulate work
|
||||
pass
|
||||
|
||||
assert any(
|
||||
"[BENCHMARK] Test Task completed in" in record.message
|
||||
for record in caplog.records
|
||||
)
|
||||
|
||||
|
||||
def test_time_it_decorator_sync(caplog):
|
||||
import logging
|
||||
|
||||
@time_it("Sync Helper")
|
||||
def my_sync_fn(x, y):
|
||||
return x + y
|
||||
|
||||
with caplog.at_level(logging.INFO):
|
||||
res = my_sync_fn(10, 20)
|
||||
|
||||
assert res == 30
|
||||
assert any(
|
||||
"[BENCHMARK] Sync Helper completed in" in record.message
|
||||
for record in caplog.records
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_time_it_decorator_async(caplog):
|
||||
import logging
|
||||
|
||||
@time_it("Async Helper")
|
||||
async def my_async_fn():
|
||||
await asyncio.sleep(0.01)
|
||||
return "done"
|
||||
|
||||
with caplog.at_level(logging.INFO):
|
||||
res = await my_async_fn()
|
||||
|
||||
assert res == "done"
|
||||
assert any(
|
||||
"[BENCHMARK] Async Helper completed in" in record.message
|
||||
for record in caplog.records
|
||||
)
|
||||
Reference in New Issue
Block a user