From 2135b967060d8aa7bc2698d6a5c805bc332b586c Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sat, 10 May 2025 15:04:56 +0200 Subject: [PATCH] Testing: check if pipeline gets stuck because of startup task (#745) * lets check if this gets stuck with postgres or not * check if it works if I add sleeps * replace startup_ledger with await ledger._check_pending_proofs_and_melt_quotes() in tests * fix typo to trigger tests again --- cashu/mint/ledger.py | 8 +++++++- tests/test_mint_init.py | 44 +++++++++++++++-------------------------- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index 09d81b7..45cc33f 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -66,7 +66,13 @@ from .tasks import LedgerTasks from .verification import LedgerVerification -class Ledger(LedgerVerification, LedgerSpendingConditions, LedgerTasks, LedgerFeatures, LedgerKeysets): +class Ledger( + LedgerVerification, + LedgerSpendingConditions, + LedgerTasks, + LedgerFeatures, + LedgerKeysets, +): backends: Mapping[Method, Mapping[Unit, LightningBackend]] = {} keysets: Dict[str, MintKeyset] = {} events = LedgerEventManager() diff --git a/tests/test_mint_init.py b/tests/test_mint_init.py index 18839a6..42b2bd4 100644 --- a/tests/test_mint_init.py +++ b/tests/test_mint_init.py @@ -176,11 +176,8 @@ async def test_startup_fakewallet_pending_quote_success(ledger: Ledger): states = await ledger.db_read.get_proofs_states([pending_proof.Y]) assert states[0].pending settings.fakewallet_payment_state = PaymentResult.SETTLED.name - # run startup routinge - await ledger.startup_ledger() - - # we need to sleep because the startup routine for checking the invoices is async - await asyncio.sleep(1) + # run startup routine + await ledger._check_pending_proofs_and_melt_quotes() # expect that no pending tokens are in db anymore melt_quotes = await ledger.crud.get_all_melt_quotes_from_pending_proofs( @@ -205,11 +202,8 @@ async def test_startup_fakewallet_pending_quote_failure(ledger: Ledger): states = await ledger.db_read.get_proofs_states([pending_proof.Y]) assert states[0].pending settings.fakewallet_payment_state = PaymentResult.FAILED.name - # run startup routinge - await ledger.startup_ledger() - - # we need to sleep because the startup routine for checking the invoices is async - await asyncio.sleep(1) + # run startup routine + await ledger._check_pending_proofs_and_melt_quotes() # expect that no pending tokens are in db anymore melt_quotes = await ledger.crud.get_all_melt_quotes_from_pending_proofs( @@ -229,11 +223,8 @@ async def test_startup_fakewallet_pending_quote_pending(ledger: Ledger): states = await ledger.db_read.get_proofs_states([pending_proof.Y]) assert states[0].pending settings.fakewallet_payment_state = PaymentResult.PENDING.name - # run startup routinge - await ledger.startup_ledger() - - # we need to sleep because the startup routine for checking the invoices is async - await asyncio.sleep(1) + # run startup routine + await ledger._check_pending_proofs_and_melt_quotes() # expect that melt quote is still pending melt_quotes = await ledger.crud.get_all_melt_quotes_from_pending_proofs( @@ -254,11 +245,8 @@ async def test_startup_fakewallet_pending_quote_unknown(ledger: Ledger): states = await ledger.db_read.get_proofs_states([pending_proof.Y]) assert states[0].pending settings.fakewallet_payment_state = PaymentResult.UNKNOWN.name - # run startup routinge - await ledger.startup_ledger() - - # we need to sleep because the startup routine for checking the invoices is async - await asyncio.sleep(1) + # run startup routine + await ledger._check_pending_proofs_and_melt_quotes() # expect that melt quote is still pending melt_quotes = await ledger.crud.get_all_melt_quotes_from_pending_proofs( @@ -299,8 +287,8 @@ async def test_startup_regtest_pending_quote_pending(wallet: Wallet, ledger: Led ) await asyncio.sleep(SLEEP_TIME) - # run startup routinge - await ledger.startup_ledger() + # run startup routine + await ledger._check_pending_proofs_and_melt_quotes() # expect that melt quote is still pending melt_quotes = await ledger.crud.get_all_melt_quotes_from_pending_proofs( @@ -349,8 +337,8 @@ async def test_startup_regtest_pending_quote_success(wallet: Wallet, ledger: Led settle_invoice(preimage=preimage) await asyncio.sleep(SLEEP_TIME) - # run startup routinge - await ledger.startup_ledger() + # run startup routine + await ledger._check_pending_proofs_and_melt_quotes() # expect that no melt quote is pending melt_quotes = await ledger.crud.get_all_melt_quotes_from_pending_proofs( @@ -400,8 +388,8 @@ async def test_startup_regtest_pending_quote_failure(wallet: Wallet, ledger: Led cancel_invoice(preimage_hash=preimage_hash) await asyncio.sleep(SLEEP_TIME) - # run startup routinge - await ledger.startup_ledger() + # run startup routine + await ledger._check_pending_proofs_and_melt_quotes() # expect that no melt quote is pending melt_quotes = await ledger.crud.get_all_melt_quotes_from_pending_proofs( @@ -466,7 +454,7 @@ async def test_startup_regtest_pending_quote_unknown(wallet: Wallet, ledger: Led await asyncio.sleep(SLEEP_TIME) # run startup routine - await ledger.startup_ledger() + await ledger._check_pending_proofs_and_melt_quotes() # expect that melt quote is still pending melt_quotes = await ledger.crud.get_all_melt_quotes_from_pending_proofs( @@ -511,7 +499,7 @@ async def test_regtest_check_nonexisting_melt_quote(wallet: Wallet, ledger: Ledg assert melt_quotes.state == MeltQuoteState.pending # run startup routine - await ledger.startup_ledger() + await ledger._check_pending_proofs_and_melt_quotes() status: PaymentStatus = await ledger.backends[Method.bolt11][ Unit.sat