mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-21 08:04:26 +01:00
tests/test_lightningd.py: add async option for pay command.
We'll need this for testing nodes going down during payment. However, there's no good way to silence the threads that I can tell, so we get a nasty backtrace from it. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -14,6 +14,7 @@ import sqlite3
|
|||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
import utils
|
import utils
|
||||||
@@ -195,21 +196,38 @@ class LightningDTests(BaseLightningDTests):
|
|||||||
l1.daemon.wait_for_log('-> CHANNELD_NORMAL')
|
l1.daemon.wait_for_log('-> CHANNELD_NORMAL')
|
||||||
l2.daemon.wait_for_log('-> CHANNELD_NORMAL')
|
l2.daemon.wait_for_log('-> CHANNELD_NORMAL')
|
||||||
|
|
||||||
def pay(self, lsrc, ldst, amt, label=None):
|
def pay(self, lsrc, ldst, amt, label=None, async=False):
|
||||||
if not label:
|
if not label:
|
||||||
label = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(20))
|
label = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(20))
|
||||||
|
|
||||||
rhash = ldst.rpc.invoice(amt, label)['rhash']
|
rhash = ldst.rpc.invoice(amt, label)['rhash']
|
||||||
assert ldst.rpc.listinvoice(label)[0]['complete'] == False
|
assert ldst.rpc.listinvoice(label)[0]['complete'] == False
|
||||||
|
|
||||||
routestep = {
|
def call_pay():
|
||||||
'msatoshi' : amt,
|
routestep = {
|
||||||
'id' : ldst.info['id'],
|
'msatoshi' : amt,
|
||||||
'delay' : 5,
|
'id' : ldst.info['id'],
|
||||||
'channel': '1:1:1'
|
'delay' : 5,
|
||||||
}
|
'channel': '1:1:1'
|
||||||
lsrc.rpc.sendpay(to_json([routestep]), rhash)
|
}
|
||||||
assert ldst.rpc.listinvoice(label)[0]['complete'] == True
|
lsrc.rpc.sendpay(to_json([routestep]), rhash, async=False)
|
||||||
|
|
||||||
|
t = threading.Thread(target=call_pay)
|
||||||
|
t.daemon = True
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
def wait_pay():
|
||||||
|
# Up to 10 seconds for payment to succeed.
|
||||||
|
start_time = time.time()
|
||||||
|
while not ldst.rpc.listinvoice(label)[0]['complete']:
|
||||||
|
if time.time() > start_time + 10:
|
||||||
|
raise TimeoutError('Payment timed out')
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
if async:
|
||||||
|
return self.executor.submit(wait_pay)
|
||||||
|
else:
|
||||||
|
return wait_pay()
|
||||||
|
|
||||||
def test_connect(self):
|
def test_connect(self):
|
||||||
l1,l2 = self.connect()
|
l1,l2 = self.connect()
|
||||||
|
|||||||
Reference in New Issue
Block a user