From 294dc5dc201ee985c9f5378482bf3fcd1511b678 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Thu, 23 Jul 2020 22:40:48 +0200 Subject: [PATCH] summary: increase test coverage --- summary/test_summary.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/summary/test_summary.py b/summary/test_summary.py index 7624495..19dc294 100644 --- a/summary/test_summary.py +++ b/summary/test_summary.py @@ -1,5 +1,7 @@ import subprocess import unittest +import time +import re from pyln.client import Plugin from pyln.testing.fixtures import * # noqa: F401,F403 @@ -20,6 +22,26 @@ def get_stub(): return plugin +def test_summary_peer_thread(node_factory): + # in order to give the PeerThread a chance in a unit test + # we need to give it a low interval + opts = {'summary-availability-interval' : 0.1} + opts.update(pluginopt) + l1, l2 = node_factory.line_graph(2, opts=opts) + + # when + s1 = l1.rpc.summary() + l2.stop() # we stop l2 and + time.sleep(0.5) # wait a bit for the PeerThread to see it + s2 = l1.rpc.summary() + + # then + avail1 = int(re.search(' ([0-9]*)% ', s1['channels'][2]).group(1)) + avail2 = int(re.search(' ([0-9]*)% ', s2['channels'][2]).group(1)) + assert(avail1 == 100) + assert(avail2 > 0 and avail2 < avail1) + + # tests the 72hr exponential availibility tracing # tests base algo and peerstate tracing def test_summary_avail_101(): @@ -147,19 +169,24 @@ def test_summary_avail_leadwin(): def test_summary_start(node_factory): + # given l1 = node_factory.get_node(options=pluginopt) + l2 = node_factory.get_node(options=pluginopt) + l1.connect(l2) + + # when s = l1.rpc.summary() + # then expected = { 'format-hint': 'simple', 'network': 'REGTEST', 'num_channels': 0, 'num_connected': 0, - 'num_gossipers': 0, + 'num_gossipers': 1, 'num_utxos': 0, 'warning_no_address': 'NO PUBLIC ADDRESSES' } - for k, v in expected.items(): assert(s[k] == v)