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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 34 additions and 24 deletions

View file

@ -80,19 +80,22 @@ async def test_create_real_invoice(client, adminkey_headers_from, inkey_headers_
assert not payment_status["paid"]
async def listen():
found_checking_id = False
async for checking_id in get_funding_source().paid_invoices_stream():
if checking_id == invoice["checking_id"]:
found_checking_id = True
return
assert found_checking_id
# wait for the backend to update the payment status
await asyncio.sleep(1)
return checking_id
async def pay():
await asyncio.sleep(3)
# wait a sec to paid_invoices_stream to start listening
await asyncio.sleep(1)
pay_real_invoice(invoice["payment_request"])
return True
checking_id, paid = await asyncio.gather(listen(), pay())
assert paid
assert checking_id == invoice["payment_hash"]
await asyncio.gather(listen(), pay())
await asyncio.sleep(3)
response = await client.get(
f'/api/v1/payments/{invoice["payment_hash"]}', headers=inkey_headers_from
)
@ -296,22 +299,26 @@ async def test_receive_real_invoice_set_pending_and_check_state(
assert not payment_status["paid"]
async def listen():
found_checking_id = False
async for checking_id in get_funding_source().paid_invoices_stream():
if checking_id == invoice["checking_id"]:
found_checking_id = True
return
assert found_checking_id
# wait for the backend to update the payment status
await asyncio.sleep(1)
return checking_id
async def pay():
await asyncio.sleep(3)
# wait a sec to paid_invoices_stream to start listening
await asyncio.sleep(1)
pay_real_invoice(invoice["payment_request"])
return True
checking_id, paid = await asyncio.gather(listen(), pay())
assert paid
assert checking_id == invoice["payment_hash"]
await asyncio.gather(listen(), pay())
await asyncio.sleep(3)
response = await client.get(
f'/api/v1/payments/{invoice["payment_hash"]}', headers=inkey_headers_from
)
assert response.status_code < 300
payment_status = response.json()
assert payment_status["paid"]