mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +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:
parent
8e0c19c76a
commit
fc24c71196
@ -14,6 +14,7 @@ import sqlite3
|
||||
import string
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import unittest
|
||||
import utils
|
||||
@ -195,21 +196,38 @@ class LightningDTests(BaseLightningDTests):
|
||||
l1.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:
|
||||
label = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(20))
|
||||
|
||||
rhash = ldst.rpc.invoice(amt, label)['rhash']
|
||||
assert ldst.rpc.listinvoice(label)[0]['complete'] == False
|
||||
|
||||
routestep = {
|
||||
'msatoshi' : amt,
|
||||
'id' : ldst.info['id'],
|
||||
'delay' : 5,
|
||||
'channel': '1:1:1'
|
||||
}
|
||||
lsrc.rpc.sendpay(to_json([routestep]), rhash)
|
||||
assert ldst.rpc.listinvoice(label)[0]['complete'] == True
|
||||
def call_pay():
|
||||
routestep = {
|
||||
'msatoshi' : amt,
|
||||
'id' : ldst.info['id'],
|
||||
'delay' : 5,
|
||||
'channel': '1:1:1'
|
||||
}
|
||||
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):
|
||||
l1,l2 = self.connect()
|
||||
|
Loading…
Reference in New Issue
Block a user