Test harness: Lightning invoice tests need a non-VoidWallet backend without hanging teardown #40
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
The libra integration test harness (
tests/conftest.py) boots LNbits in-process inside anasgi_lifespan.LifespanManager. Lightning-invoice-generation tests need a real-ish backend (i.e. notVoidWallet, which 500s with"VoidWallet cannot create invoices.").FakeWalletis the right candidate per CLAUDE.md and works in standalone Python — but switching the test harness to it (settings.lnbits_backend_wallet_class = "FakeWallet"orLNBITS_BACKEND_WALLET_CLASS=FakeWallet) makes theLifespanManagerteardown hang indefinitely under anyio'sTestRunner. The Lightning-side background tasks (probably one ofinvoice_listener,internal_invoice_listener, or the FakeWalletpending_invoicesnotifier) don't unwind cleanly when the event loop is shut down by pytest.Symptoms
lnbits_backend_wallet_classtoFakeWallet.test_smoke.py.pytesttimeout never fires; only an externaltimeout 90SIGTERM kills it.What we've tried
LNBITS_BACKEND_WALLET_CLASS=FakeWalletat the top ofconftest.py(before any lnbits import) — env var is picked up but settings are already constructed; pytest's plugin discovery transitively importslnbits.settingsfirst.lnbits_settings.lnbits_backend_wallet_class = "FakeWallet"immediately after import — flips the in-memory value successfully (verified viaprint()), the LNbits boot log then saysFunding source: FakeWallet, invoice generation succeeds. But teardown hangs._settings_cleanup's post-PURE reapply step — same result: works at runtime, hangs at teardown.What we've shipped instead
tests/test_lightning_api.pykeeps 4 tests that don't need invoice generation (auth gates, 404 on unknown payment_hash, 401 on missing auth). The 3 tests that need an actual generated invoice are markedpytest.mark.skipwith aNEEDS_LIGHTNING_BACKENDmarker pointing at this issue:test_user_can_generate_invoice_for_own_balancetest_super_user_can_generate_invoice_for_another_usertest_record_payment_pending_invoice_returns_400The skipped tests carry full implementations — flipping them back on is a one-line change once the teardown issue is fixed.
Possible directions
create_payment_request/get_standalone_paymentwith hand-written async functions that return canned LNbits-shape payloads. No real LNbits Lightning machinery involved. Doesn't catch breakage in libra's call to LNbits, but covers libra's own logic.(3) is probably the cheapest path back to coverage. (1) is the right long-term fix if the bug is in lnbits.
Scope
lnbits/main/tests(it may already be a known LNbits-side issue).