mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-10-05 20:28:23 +00:00
test: cover busy_timeout connect_arg and refund single-attempt side effects
This commit is contained in:
@@ -56,9 +56,40 @@ def test_non_sqlite_backend_enables_pre_ping_automatically(
|
|||||||
|
|
||||||
assert created is fake_engine
|
assert created is fake_engine
|
||||||
assert factory.call_args.kwargs["pool_pre_ping"] is True
|
assert factory.call_args.kwargs["pool_pre_ping"] is True
|
||||||
|
assert "timeout" not in factory.call_args.kwargs["connect_args"]
|
||||||
assert listen.call_count == 2
|
assert listen.call_count == 2
|
||||||
|
|
||||||
|
|
||||||
|
def test_file_sqlite_sets_busy_timeout_connect_arg(
|
||||||
|
monkeypatch: pytest.MonkeyPatch, tmp_path: object
|
||||||
|
) -> None:
|
||||||
|
monkeypatch.setattr(settings, "database_busy_timeout", 42.0)
|
||||||
|
fake_engine = MagicMock()
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch.object(db, "create_async_engine", return_value=fake_engine) as factory,
|
||||||
|
patch.object(db.event, "listen"),
|
||||||
|
):
|
||||||
|
create_db_engine(f"sqlite+aiosqlite:///{tmp_path}/busy.db")
|
||||||
|
|
||||||
|
assert factory.call_args.kwargs["connect_args"]["timeout"] == 42.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_memory_sqlite_omits_busy_timeout_connect_arg(
|
||||||
|
monkeypatch: pytest.MonkeyPatch,
|
||||||
|
) -> None:
|
||||||
|
monkeypatch.setattr(settings, "database_busy_timeout", 42.0)
|
||||||
|
fake_engine = MagicMock()
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch.object(db, "create_async_engine", return_value=fake_engine) as factory,
|
||||||
|
patch.object(db.event, "listen"),
|
||||||
|
):
|
||||||
|
create_db_engine("sqlite+aiosqlite://")
|
||||||
|
|
||||||
|
assert "timeout" not in factory.call_args.kwargs["connect_args"]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_every_created_engine_warns_for_long_checkouts(
|
async def test_every_created_engine_warns_for_long_checkouts(
|
||||||
monkeypatch: pytest.MonkeyPatch, tmp_path: object
|
monkeypatch: pytest.MonkeyPatch, tmp_path: object
|
||||||
|
|||||||
@@ -13,9 +13,11 @@ from routstr.upstream.base import BaseUpstreamProvider
|
|||||||
async def test_send_refund_does_not_retry_ambiguous_token_creation() -> None:
|
async def test_send_refund_does_not_retry_ambiguous_token_creation() -> None:
|
||||||
provider = object.__new__(BaseUpstreamProvider)
|
provider = object.__new__(BaseUpstreamProvider)
|
||||||
send_token = AsyncMock(side_effect=httpx.ReadTimeout("swap response lost"))
|
send_token = AsyncMock(side_effect=httpx.ReadTimeout("swap response lost"))
|
||||||
|
store = AsyncMock()
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch("routstr.upstream.base.send_token", send_token),
|
patch("routstr.upstream.base.send_token", send_token),
|
||||||
|
patch("routstr.upstream.base.store_cashu_transaction", store),
|
||||||
pytest.raises(HTTPException) as raised,
|
pytest.raises(HTTPException) as raised,
|
||||||
):
|
):
|
||||||
await provider.send_refund(10, "sat", mint="https://mint.test")
|
await provider.send_refund(10, "sat", mint="https://mint.test")
|
||||||
@@ -24,3 +26,24 @@ async def test_send_refund_does_not_retry_ambiguous_token_creation() -> None:
|
|||||||
send_token.assert_awaited_once_with(
|
send_token.assert_awaited_once_with(
|
||||||
10, unit="sat", mint_url="https://mint.test"
|
10, unit="sat", mint_url="https://mint.test"
|
||||||
)
|
)
|
||||||
|
store.assert_not_awaited()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_send_refund_does_not_retry_or_store_on_generic_failure() -> None:
|
||||||
|
provider = object.__new__(BaseUpstreamProvider)
|
||||||
|
send_token = AsyncMock(side_effect=Exception("mint rejected swap"))
|
||||||
|
store = AsyncMock()
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch("routstr.upstream.base.send_token", send_token),
|
||||||
|
patch("routstr.upstream.base.store_cashu_transaction", store),
|
||||||
|
pytest.raises(HTTPException) as raised,
|
||||||
|
):
|
||||||
|
await provider.send_refund(10, "sat", mint="https://mint.test")
|
||||||
|
|
||||||
|
assert raised.value.status_code == 401
|
||||||
|
send_token.assert_awaited_once_with(
|
||||||
|
10, unit="sat", mint_url="https://mint.test"
|
||||||
|
)
|
||||||
|
store.assert_not_awaited()
|
||||||
|
|||||||
Reference in New Issue
Block a user