pytest: Stabilize test_autocleaninvoice

The RPC calls aren't really free, so let's wait for absolute times, computed
from the `start_time` instead.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-05-18 11:36:41 -04:00 committed by Rusty Russell
parent e117d25c1f
commit a35cc9a79f
1 changed files with 5 additions and 4 deletions

View File

@ -425,6 +425,7 @@ class LightningDTests(BaseLightningDTests):
def test_autocleaninvoice(self):
l1 = self.node_factory.get_node()
start_time = time.time()
l1.rpc.autocleaninvoice(cycle_seconds=8, expired_by=2)
l1.rpc.invoice(msatoshi=12300, label='inv1', description='1', expiry=4)
@ -435,7 +436,7 @@ class LightningDTests(BaseLightningDTests):
assert len(l1.rpc.listinvoices('inv1')['invoices']) == 1
assert len(l1.rpc.listinvoices('inv2')['invoices']) == 1
time.sleep(6) # total 6
time.sleep(start_time - time.time() + 6) # total 6
# Both should still be there - auto clean cycle not started.
# inv1 should be expired
assert len(l1.rpc.listinvoices('inv1')['invoices']) == 1
@ -443,19 +444,19 @@ class LightningDTests(BaseLightningDTests):
assert len(l1.rpc.listinvoices('inv2')['invoices']) == 1
assert l1.rpc.listinvoices('inv2')['invoices'][0]['status'] != 'expired'
time.sleep(4) # total 10
time.sleep(start_time - time.time() + 10) # total 10
# inv1 should have deleted, inv2 still there and unexpired.
assert len(l1.rpc.listinvoices('inv1')['invoices']) == 0
assert len(l1.rpc.listinvoices('inv2')['invoices']) == 1
assert l1.rpc.listinvoices('inv2')['invoices'][0]['status'] != 'expired'
time.sleep(4) # total 14
time.sleep(start_time - time.time() + 14) # total 14
# inv2 should still be there, but expired
assert len(l1.rpc.listinvoices('inv1')['invoices']) == 0
assert len(l1.rpc.listinvoices('inv2')['invoices']) == 1
assert l1.rpc.listinvoices('inv2')['invoices'][0]['status'] == 'expired'
time.sleep(4) # total 18
time.sleep(start_time - time.time() + 18) # total 18
# Everything deleted
assert len(l1.rpc.listinvoices('inv1')['invoices']) == 0
assert len(l1.rpc.listinvoices('inv2')['invoices']) == 0