From 006ab1e3670ec5d39c561be44e3583f676b506a8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 5 May 2020 10:43:50 +0930 Subject: [PATCH] pytest: test loading all plugins at once, including failing ones. We modify the slow_init() so it doesn't go too slowly for this test. This demonstrates a crash, where we currently try to fail a command multiple times. Signed-off-by: Rusty Russell --- tests/plugins/slow_init.py | 3 ++- tests/test_plugin.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/plugins/slow_init.py b/tests/plugins/slow_init.py index 82881d7d3..546135b22 100755 --- a/tests/plugins/slow_init.py +++ b/tests/plugins/slow_init.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 from pyln.client import Plugin +import os import time plugin = Plugin() @@ -8,7 +9,7 @@ plugin = Plugin() @plugin.init() def init(options, configuration, plugin): plugin.log("slow_init.py initializing {}".format(configuration)) - time.sleep(21) + time.sleep(int(os.getenv('SLOWINIT_TIME', "0"))) plugin.run() diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 16e45f94c..6befcfad1 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -194,6 +194,7 @@ def test_plugin_dir(node_factory): def test_plugin_slowinit(node_factory): """Tests that the 'plugin' RPC command times out if plugin doesnt respond""" + os.environ['SLOWINIT_TIME'] = '21' n = node_factory.get_node() with pytest.raises(RpcError, match="Timed out while waiting for plugin response"): @@ -205,6 +206,7 @@ def test_plugin_slowinit(node_factory): n.rpc.plugin_list() +@pytest.mark.xfail(strict=True) def test_plugin_command(node_factory): """Tests the 'plugin' RPC command""" n = node_factory.get_node() @@ -259,6 +261,15 @@ def test_plugin_command(node_factory): with pytest.raises(RpcError, match=r"Plugin exited before completing handshake."): n2.rpc.plugin_start(plugin=os.path.join(os.getcwd(), "tests/plugins/broken.py")) + # Test that we can add a directory with more than one new plugin in it. + try: + n.rpc.plugin_startdir(os.path.join(os.getcwd(), "tests/plugins")) + except RpcError: + pass + + # Usually, it crashes after the above return. + n.rpc.stop() + def test_plugin_disable(node_factory): """--disable-plugin works"""