mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
testing: test that RPC calls made in shutdown fail and receive error code -5
and the two conditions in which plugins can receive shutdown notification
This commit is contained in:
committed by
Rusty Russell
parent
0388314ef8
commit
89cbdf4dce
@@ -2,9 +2,10 @@
|
||||
"""Plugin to be used to test miscellaneous notifications.
|
||||
"""
|
||||
|
||||
from pyln.client import Plugin
|
||||
from pyln.client import Plugin, RpcError
|
||||
from time import sleep
|
||||
import sys
|
||||
import pytest
|
||||
|
||||
plugin = Plugin()
|
||||
|
||||
@@ -29,6 +30,23 @@ def channel_state_changed(plugin, channel_state_changed, **kwargs):
|
||||
|
||||
@plugin.subscribe("shutdown")
|
||||
def shutdown(plugin, **kwargs):
|
||||
plugin.log("received shutdown notification")
|
||||
|
||||
# 'shutdown' notification can be called in two ways, from `plugin stop` or from
|
||||
# lightningd's shutdown loop, we test which one by making `getinfo` call
|
||||
try:
|
||||
plugin.rpc.getinfo()
|
||||
plugin.rpc.datastore(key='test', string='Allowed', mode="create-or-append")
|
||||
plugin.log("datastore success")
|
||||
except RpcError as e:
|
||||
if e.error == {'code': -5, 'message': 'lightningd is shutting down'}:
|
||||
# JSON RPC is disabled by now, but can do logging
|
||||
with pytest.raises(RpcError, match=r'-5.*lightningd is shutting down'):
|
||||
plugin.rpc.datastore(key='test', string='Not allowed', mode="create-or-append")
|
||||
plugin.log("datastore failed")
|
||||
else:
|
||||
raise
|
||||
|
||||
plugin.log("delaying shutdown with 5s")
|
||||
sleep(5)
|
||||
sys.exit(0)
|
||||
|
||||
Reference in New Issue
Block a user