fix: non-blocking relay publishes in send_nostr_dm (#3925)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
Vlad Stan
parent
9d9ce63c82
commit
29e980dd67
@@ -39,6 +39,7 @@ from lnbits.core.services.notifications import (
|
||||
send_nostr_notification,
|
||||
send_nostr_notifications,
|
||||
send_notification,
|
||||
send_notification_in_background,
|
||||
send_payment_notification,
|
||||
send_payment_push_notification,
|
||||
send_push_notification,
|
||||
@@ -117,7 +118,7 @@ async def test_send_admin_and_user_notification_use_expected_targets(
|
||||
settings: Settings, mocker: MockerFixture
|
||||
):
|
||||
send_mock = mocker.patch(
|
||||
"lnbits.core.services.notifications.send_notification",
|
||||
"lnbits.core.services.notifications.send_notification_in_background",
|
||||
mocker.AsyncMock(),
|
||||
)
|
||||
original_chat_id = settings.lnbits_telegram_notifications_chat_id
|
||||
@@ -159,6 +160,45 @@ async def test_send_admin_and_user_notification_use_expected_targets(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_send_notification_in_background_schedules_notification(
|
||||
mocker: MockerFixture,
|
||||
):
|
||||
scheduled = []
|
||||
|
||||
def create_task(coro):
|
||||
scheduled.append(coro)
|
||||
coro.close()
|
||||
return mocker.Mock()
|
||||
|
||||
create_task_mock = mocker.patch(
|
||||
"lnbits.core.services.notifications.create_task",
|
||||
side_effect=create_task,
|
||||
)
|
||||
send_mock = mocker.patch(
|
||||
"lnbits.core.services.notifications.send_notification",
|
||||
mocker.AsyncMock(),
|
||||
)
|
||||
|
||||
await send_notification_in_background(
|
||||
"chat-id",
|
||||
["alice@example.com"],
|
||||
["admin@example.com"],
|
||||
"hello",
|
||||
"settings_update",
|
||||
)
|
||||
|
||||
create_task_mock.assert_called_once()
|
||||
send_mock.assert_called_once_with(
|
||||
"chat-id",
|
||||
["alice@example.com"],
|
||||
["admin@example.com"],
|
||||
"hello",
|
||||
"settings_update",
|
||||
)
|
||||
assert len(scheduled) == 1
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_send_notification_uses_available_channels_and_swallows_exceptions(
|
||||
settings: Settings, mocker: MockerFixture
|
||||
|
||||
Reference in New Issue
Block a user