Skip to content

Commit ce550df

Browse files
committed
pytest: detect warnings, too.
Since we turned many errors into warnings, we want our tests to fail when they happen unexpectedly. We make WARNING clear in the strings we print, too, to help out. Signed-off-by: Rusty Russell <[email protected]>
1 parent 24ba866 commit ce550df

File tree

8 files changed

+31
-14
lines changed

8 files changed

+31
-14
lines changed

contrib/pyln-testing/pyln/testing/fixtures.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ def map_node_error(nodes, f, msg):
229229
map_node_error(nf.nodes, printValgrindErrors, "reported valgrind errors")
230230
map_node_error(nf.nodes, printCrashLog, "had crash.log files")
231231
map_node_error(nf.nodes, lambda n: not n.allow_broken_log and n.daemon.is_in_log(r'\*\*BROKEN\*\*'), "had BROKEN messages")
232+
map_node_error(nf.nodes, lambda n: not n.allow_warning and n.daemon.is_in_log(r' WARNING:'), "had warning messages")
232233
map_node_error(nf.nodes, checkReconnect, "had unexpected reconnections")
233234
map_node_error(nf.nodes, checkBadGossip, "had bad gossip messages")
234235
map_node_error(nf.nodes, lambda n: n.daemon.is_in_log('Bad reestablish'), "had bad reestablish")

contrib/pyln-testing/pyln/testing/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,15 +618,19 @@ def call(self, method, payload=None):
618618

619619
class LightningNode(object):
620620
def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fail=False,
621-
may_reconnect=False, allow_broken_log=False,
622-
allow_bad_gossip=False, db=None, port=None, disconnect=None, random_hsm=None, options=None,
621+
may_reconnect=False,
622+
allow_broken_log=False,
623+
allow_warning=False,
624+
allow_bad_gossip=False,
625+
db=None, port=None, disconnect=None, random_hsm=None, options=None,
623626
**kwargs):
624627
self.bitcoin = bitcoind
625628
self.executor = executor
626629
self.may_fail = may_fail
627630
self.may_reconnect = may_reconnect
628631
self.allow_broken_log = allow_broken_log
629632
self.allow_bad_gossip = allow_bad_gossip
633+
self.allow_warning = allow_warning
630634
self.db = db
631635

632636
# Assume successful exit
@@ -1203,6 +1207,7 @@ def split_options(self, opts):
12031207
'disconnect',
12041208
'may_fail',
12051209
'allow_broken_log',
1210+
'allow_warning',
12061211
'may_reconnect',
12071212
'random_hsm',
12081213
'feerates',

lightningd/peer_control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ void channel_errmsg(struct channel *channel,
396396
* and we would close the channel on them. We now support warnings
397397
* for this case. */
398398
if (warning) {
399-
channel_fail_reconnect_later(channel, "%s: (ignoring) %s",
399+
channel_fail_reconnect_later(channel, "%s WARNING: %s",
400400
channel->owner->name, desc);
401401
return;
402402
}

tests/test_closing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2523,7 +2523,10 @@ def test_shutdown(node_factory):
25232523
@flaky
25242524
@unittest.skipIf(not DEVELOPER, "needs to set upfront_shutdown_script")
25252525
def test_option_upfront_shutdown_script(node_factory, bitcoind, executor):
2526-
l1 = node_factory.get_node(start=False)
2526+
# There's a workaround in channeld, that it treats incoming errors
2527+
# before both sides are locked in as warnings; this happens in
2528+
# this test, so l1 reports the error as a warning!
2529+
l1 = node_factory.get_node(start=False, allow_warning=True)
25272530
# Insist on upfront script we're not going to match.
25282531
l1.daemon.env["DEV_OPENINGD_UPFRONT_SHUTDOWN_SCRIPT"] = "76a91404b61f7dc1ea0dc99424464cc4064dc564d91e8988ac"
25292532
l1.start()

tests/test_connection.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,8 +1956,10 @@ def test_update_fee(node_factory, bitcoind):
19561956

19571957
@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1")
19581958
def test_fee_limits(node_factory, bitcoind):
1959-
l1, l2, l3, l4 = node_factory.get_nodes(4, opts=[{'dev-max-fee-multiplier': 5, 'may_reconnect': True},
1960-
{'dev-max-fee-multiplier': 5, 'may_reconnect': True},
1959+
l1, l2, l3, l4 = node_factory.get_nodes(4, opts=[{'dev-max-fee-multiplier': 5, 'may_reconnect': True,
1960+
'allow_warning': True},
1961+
{'dev-max-fee-multiplier': 5, 'may_reconnect': True,
1962+
'allow_warning': True},
19611963
{'ignore-fee-limits': True, 'may_reconnect': True},
19621964
{}])
19631965

tests/test_misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ def test_bitcoind_goes_backwards(node_factory, bitcoind):
13361336
@flaky
13371337
def test_reserve_enforcement(node_factory, executor):
13381338
"""Channeld should disallow you spending into your reserve"""
1339-
l1, l2 = node_factory.line_graph(2, opts={'may_reconnect': True})
1339+
l1, l2 = node_factory.line_graph(2, opts={'may_reconnect': True, 'allow_warning': True})
13401340

13411341
# Pay 1000 satoshi to l2.
13421342
l1.pay(l2, 1000000)

tests/test_pay.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ def test_pay0(node_factory):
234234
def test_pay_disconnect(node_factory, bitcoind):
235235
"""If the remote node has disconnected, we fail payment, but can try again when it reconnects"""
236236
l1, l2 = node_factory.line_graph(2, opts={'dev-max-fee-multiplier': 5,
237-
'may_reconnect': True})
237+
'may_reconnect': True,
238+
'allow_warning': True})
238239

239240
# Dummy payment to kick off update_fee messages
240241
l1.pay(l2, 1000)
@@ -261,7 +262,7 @@ def test_pay_disconnect(node_factory, bitcoind):
261262
l1.set_feerates((10**6, 1000**6, 1000**6, 1000**6), False)
262263

263264
# Wait for l1 notice
264-
l1.daemon.wait_for_log(r'Peer transient failure in CHANNELD_NORMAL: channeld: .*: update_fee \d+ outside range 1875-75000')
265+
l1.daemon.wait_for_log(r'Peer transient failure in CHANNELD_NORMAL: channeld WARNING: .*: update_fee \d+ outside range 1875-75000')
265266

266267
# Make l2 fail hard.
267268
l2.rpc.close(l1.info['id'], unilateraltimeout=1)

tests/test_plugin.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,16 @@ def test_plugin_connected_hook_chaining(node_factory):
398398
l1 is configured to accept connections from l2, but not from l3.
399399
we check that logger_a is always called and logger_b only for l2.
400400
"""
401-
opts = [{'plugin': [
402-
os.path.join(os.getcwd(), 'tests/plugins/peer_connected_logger_a.py'),
403-
os.path.join(os.getcwd(), 'tests/plugins/reject.py'),
404-
os.path.join(os.getcwd(), 'tests/plugins/peer_connected_logger_b.py'),
405-
]}, {}, {}]
401+
opts = [{'plugin':
402+
[os.path.join(os.getcwd(),
403+
'tests/plugins/peer_connected_logger_a.py'),
404+
os.path.join(os.getcwd(),
405+
'tests/plugins/reject.py'),
406+
os.path.join(os.getcwd(),
407+
'tests/plugins/peer_connected_logger_b.py')],
408+
'allow_warning': True},
409+
{},
410+
{'allow_warning': True}]
406411

407412
l1, l2, l3 = node_factory.get_nodes(3, opts=opts)
408413
l2id = l2.info['id']

0 commit comments

Comments
 (0)