diff --git a/tests/benchmark.py b/tests/benchmark.py index 81ab387d5..ec0062e82 100644 --- a/tests/benchmark.py +++ b/tests/benchmark.py @@ -218,4 +218,13 @@ def test_spam_commands(node_factory, bitcoind, benchmark): plugin = os.path.join(os.getcwd(), "tests/plugins/test_libplugin") l1 = get_bench_node(node_factory, extra_options={"plugin": plugin}) + # This calls "batch" 1M times (which doesn't need a transaction) benchmark(l1.rpc.spamcommand, 1_000_000) + + +def test_spam_listcommands(node_factory, bitcoind, benchmark): + plugin = os.path.join(os.getcwd(), "tests/plugins/test_libplugin") + l1 = get_bench_node(node_factory, extra_options={"plugin": plugin}) + + # This calls "listinvoice" 100,000 times (which doesn't need a transaction commit) + benchmark(l1.rpc.spamlistcommand, 100_000) diff --git a/tests/plugins/test_libplugin.c b/tests/plugins/test_libplugin.c index 2abf1f7f4..c51ab55be 100644 --- a/tests/plugins/test_libplugin.c +++ b/tests/plugins/test_libplugin.c @@ -234,6 +234,26 @@ static struct command_result *json_spamcommand(struct command *cmd, return batch_done(cmd, batch); } +static struct command_result *json_spamlistcommand(struct command *cmd, + const char *buf, + const jsmntok_t *params) +{ + u64 *iterations; + struct request_batch *batch; + + if (!param(cmd, buf, params, + p_req("iterations", param_u64, &iterations), + NULL)) + return command_param_failed(); + + batch = request_batch_new(cmd, NULL, spam_errcb, spam_done, NULL); + for (size_t i = 0; i < *iterations; i++) { + struct out_req *req = add_to_batch(cmd, batch, "listinvoices"); + send_outreq(req); + } + return batch_done(cmd, batch); +} + static char *set_dynamic(struct plugin *plugin, const char *arg, @@ -312,6 +332,10 @@ static const struct plugin_command commands[] = { { "spamcommand", json_spamcommand, }, + { + "spamlistcommand", + json_spamlistcommand, + }, }; static const char *before[] = { "dummy", NULL };