test: cover busy_timeout connect_arg and refund single-attempt side effects

This commit is contained in:
9qeklajc
2026-08-25 01:47:26 +02:00
parent f6e71e1512
commit aae2c9059e
2 changed files with 54 additions and 0 deletions
+31
View File
@@ -56,9 +56,40 @@ def test_non_sqlite_backend_enables_pre_ping_automatically(
assert created is fake_engine
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
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
async def test_every_created_engine_warns_for_long_checkouts(
monkeypatch: pytest.MonkeyPatch, tmp_path: object
+23
View File
@@ -13,9 +13,11 @@ from routstr.upstream.base import BaseUpstreamProvider
async def test_send_refund_does_not_retry_ambiguous_token_creation() -> None:
provider = object.__new__(BaseUpstreamProvider)
send_token = AsyncMock(side_effect=httpx.ReadTimeout("swap response lost"))
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")
@@ -24,3 +26,24 @@ async def test_send_refund_does_not_retry_ambiguous_token_creation() -> None:
send_token.assert_awaited_once_with(
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()