From f2d67f88c0aa9bd4d58f51bbfc0a55c005dd87c7 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 7 Sep 2017 12:33:55 -0700 Subject: [PATCH] pytest: Run sendpay in a future so it doesn't complain about failing For the permfail tests the sendpay call is supposed to fail, so this was printing stacktraces upon success. Running in futures captures any thrown exceptions and rethrows them when calling `result()`, in our case we just ignore them. Signed-off-by: Christian Decker --- tests/test_lightningd.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index acc1898a6..4f4736c89 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -199,14 +199,12 @@ class LightningDTests(BaseLightningDTests): rhash = ldst.rpc.invoice(amt, label)['rhash'] assert ldst.rpc.listinvoice(label)[0]['complete'] == False - 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) + routestep = { + 'msatoshi' : amt, + 'id' : ldst.info['id'], + 'delay' : 5, + 'channel': '1:1:1' + } def wait_pay(): # Up to 10 seconds for payment to succeed. @@ -217,12 +215,10 @@ class LightningDTests(BaseLightningDTests): time.sleep(0.1) if async: - t = threading.Thread(target=call_pay) - t.daemon = True - t.start() + self.executor.submit(lsrc.rpc.sendpay, to_json([routestep]), rhash, async=False) return self.executor.submit(wait_pay) else: - call_pay() + lsrc.rpc.sendpay(to_json([routestep]), rhash, async=False) def test_connect(self): l1,l2 = self.connect() @@ -469,7 +465,7 @@ class LightningDTests(BaseLightningDTests): self.fund_channel(l1, l2, 10**6) # This will fail at l2's end. - t=self.pay(l1,l2,200000000,async=True) + t=self.pay(l1, l2, 200000000, async=True) l2.daemon.wait_for_log('dev_disconnect permfail') l2.daemon.wait_for_log('sendrawtx exit 0')