From ce0421f8c8597014437a1099429c8492465d4e20 Mon Sep 17 00:00:00 2001 From: jerryfletcher21 Date: Fri, 9 May 2025 22:36:27 +0200 Subject: [PATCH] add option for timing issues in tests On my powerful machine, running tests resulted in some errors. After a bit of digging I found out that it was a timing issues. This PR adds a config option TIMING_EXTRA_IN_TESTS that when set to True, it take some time where it should so that the tests do not fail. If the config option is not present (default) nothing is changed. I had this issue very sporadically on my laptop, and every time when running on an other powerful machine. --- api/logics.py | 14 ++++++++++++++ api/management/commands/follow_invoices.py | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/api/logics.py b/api/logics.py index d518415a..16adb1a4 100644 --- a/api/logics.py +++ b/api/logics.py @@ -675,6 +675,20 @@ class Logics: # Create onchain_payment onchain_payment = OnchainPayment.objects.create(receiver=user) + if \ + config("TIMING_EXTRA_IN_TESTS", cast=bool, default=False) and \ + config("TESTING", cast=bool, default=False) and \ + config("LNVENDOR", cast=str, default="LND") == "CLN": + import time + retries = 0 + while onchain_payment.balance.onchain_confirmed == 0: + retries += 1 + if retries > 30: + break + print("TIMING_EXTRA_IN_TESTS: onchain_payment.balance.onchain_confirmed is not 0, sleeping 2s") + time.sleep(2) + onchain_payment = OnchainPayment.objects.create(receiver=user) + # Compute a safer available onchain liquidity: (confirmed_utxos - reserve - pending_outgoing_txs)) # Accounts for already committed outgoing TX for previous users. confirmed = onchain_payment.balance.onchain_confirmed diff --git a/api/management/commands/follow_invoices.py b/api/management/commands/follow_invoices.py index e6443a18..e4fbb76a 100644 --- a/api/management/commands/follow_invoices.py +++ b/api/management/commands/follow_invoices.py @@ -61,6 +61,13 @@ class Command(BaseCommand): INVGEN / LOCKED status and do InvoiceLookupV2 every X seconds to update their status. """ + if \ + config("TIMING_EXTRA_IN_TESTS", cast=bool, default=False) and \ + config("TESTING", cast=bool, default=False) and \ + config("LNVENDOR", cast=str, default="LND") == "LND": + print("TIMING_EXTRA_IN_TESTS: follow_hold_invoices LND, sleeping 0.2s") + time.sleep(0.2) + # time it for debugging t0 = time.time()