test: fix flaky regtest (#2616)

* add log for invoice success
* add internal flag
* sleeping inside the tasks to not block
* sleep was wrong decrease wait time
This commit is contained in:
dni ⚡
2024-07-31 11:41:19 +02:00
committed by GitHub
parent b41705167f
commit ffba71c0ce
5 changed files with 34 additions and 24 deletions
+1 -1
View File
@@ -365,7 +365,7 @@ async def pay_invoice(
)
if wallet and updated:
await send_payment_notification(wallet, updated)
logger.debug(f"payment successful {payment.checking_id}")
logger.success(f"payment successful {payment.checking_id}")
elif payment.checking_id is None and payment.ok is False:
# payment failed
logger.debug(f"payment failed {temp_id}, {payment.error_message}")
+2 -2
View File
@@ -90,7 +90,7 @@ def register_http_exception_handler(app: FastAPI):
def register_payment_error_handler(app: FastAPI):
@app.exception_handler(PaymentError)
async def payment_error_handler(request: Request, exc: PaymentError):
logger.error(f"PaymentError: {exc.message}, {exc.status}")
logger.error(f"{exc.message}, {exc.status}")
return JSONResponse(
status_code=520,
content={"detail": exc.message, "status": exc.status},
@@ -100,7 +100,7 @@ def register_payment_error_handler(app: FastAPI):
def register_invoice_error_handler(app: FastAPI):
@app.exception_handler(InvoiceError)
async def invoice_error_handler(request: Request, exc: InvoiceError):
logger.error(f"InvoiceError: {exc.message}, Status: {exc.status}")
logger.error(f"{exc.message}, Status: {exc.status}")
return JSONResponse(
status_code=520,
content={"detail": exc.message, "status": exc.status},
+6 -7
View File
@@ -110,8 +110,8 @@ async def internal_invoice_listener():
"""
while settings.lnbits_running:
checking_id = await internal_invoice_queue.get()
logger.info("> got internal payment notification", checking_id)
create_task(invoice_callback_dispatcher(checking_id))
logger.info(f"got an internal payment notification {checking_id}")
create_task(invoice_callback_dispatcher(checking_id, is_internal=True))
async def invoice_listener():
@@ -123,7 +123,7 @@ async def invoice_listener():
"""
funding_source = get_funding_source()
async for checking_id in funding_source.paid_invoices_stream():
logger.info("> got a payment notification", checking_id)
logger.info(f"got a payment notification {checking_id}")
create_task(invoice_callback_dispatcher(checking_id))
@@ -171,16 +171,13 @@ async def check_pending_payments():
await asyncio.sleep(60 * 30) # every 30 minutes
async def invoice_callback_dispatcher(checking_id: str):
async def invoice_callback_dispatcher(checking_id: str, is_internal: bool = False):
"""
Takes an incoming payment, checks its status, and dispatches it to
invoice_listeners from core and extensions.
"""
payment = await get_standalone_payment(checking_id, incoming=True)
if payment and payment.is_in:
logger.trace(
f"invoice listeners: sending invoice callback for payment {checking_id}"
)
status = await payment.check_status()
await update_payment_details(
checking_id=payment.checking_id,
@@ -188,6 +185,8 @@ async def invoice_callback_dispatcher(checking_id: str):
preimage=status.preimage,
status=PaymentState.SUCCESS,
)
internal = "internal" if is_internal else ""
logger.success(f"{internal} invoice {checking_id} settled")
for name, send_chan in invoice_listeners.items():
logger.trace(f"invoice listeners: sending to `{name}`")
await send_chan.put(payment)