Skip to content

Commit 41f254d

Browse files
committed
pytest: test for 1M JSONRPC calls which don't need transactions.
To measure the improvement (if any) if we don't actually create empty transactions. Signed-off-by: Rusty Russell <[email protected]>
1 parent 025e7d9 commit 41f254d

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

tests/plugins/test_libplugin.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,44 @@ static struct command_result *json_checkthis(struct command *cmd,
197197
return send_outreq(req);
198198
}
199199

200+
static struct command_result *spam_done(struct command *cmd, void *unused)
201+
{
202+
return command_success(cmd, json_out_obj(cmd, NULL, NULL));
203+
}
204+
205+
static struct command_result *spam_errcb(struct command *cmd,
206+
const char *method,
207+
const char *buf,
208+
const jsmntok_t *tok,
209+
void *unused)
210+
{
211+
plugin_err(cmd->plugin, "%.*s",
212+
json_tok_full_len(tok),
213+
json_tok_full(buf, tok));
214+
}
215+
216+
static struct command_result *json_spamcommand(struct command *cmd,
217+
const char *buf,
218+
const jsmntok_t *params)
219+
{
220+
u64 *iterations;
221+
struct request_batch *batch;
222+
223+
if (!param(cmd, buf, params,
224+
p_req("iterations", param_u64, &iterations),
225+
NULL))
226+
return command_param_failed();
227+
228+
batch = request_batch_new(cmd, NULL, spam_errcb, spam_done, NULL);
229+
for (size_t i = 0; i < *iterations; i++) {
230+
struct out_req *req = add_to_batch(cmd, batch, "batching");
231+
json_add_bool(req->js, "enable", true);
232+
send_outreq(req);
233+
}
234+
return batch_done(cmd, batch);
235+
}
236+
237+
200238
static char *set_dynamic(struct plugin *plugin,
201239
const char *arg,
202240
bool check_only,
@@ -270,6 +308,10 @@ static const struct plugin_command commands[] = { {
270308
"checkthis",
271309
json_checkthis,
272310
},
311+
{
312+
"spamcommand",
313+
json_spamcommand,
314+
},
273315
};
274316

275317
static const char *before[] = { "dummy", NULL };

tests/test_plugin.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4663,3 +4663,23 @@ def test_openchannel_hook_channel_type(node_factory, bitcoind):
46634663
l2.daemon.wait_for_log(r"plugin-openchannel_hook_accepter.py: accept by design: channel_type {'bits': \[12, 22\], 'names': \['static_remotekey/even', 'anchors/even'\]}")
46644664
else:
46654665
l2.daemon.wait_for_log(r"plugin-openchannel_hook_accepter.py: accept by design: channel_type {'bits': \[12\], 'names': \['static_remotekey/even'\]}")
4666+
4667+
4668+
@pytest.mark.slow_test
4669+
def test_spam_commands(node_factory, bitcoind):
4670+
plugin = os.path.join(os.getcwd(), "tests/plugins/test_libplugin")
4671+
l1 = node_factory.get_node(options={"plugin": plugin, 'log-level': 'info'},
4672+
start=False)
4673+
4674+
# Memleak detection here creates significant overhead!
4675+
del l1.daemon.env["LIGHTNINGD_DEV_MEMLEAK"]
4676+
# Don't bother recording all our io.
4677+
del l1.daemon.opts['dev-save-plugin-io']
4678+
l1.start()
4679+
4680+
start_time = time.time()
4681+
l1.rpc.spamcommand(1_000_000)
4682+
duration = time.time() - start_time
4683+
4684+
# Change 100 to 0 to get test to fail so you can see the result!
4685+
assert duration < 100

0 commit comments

Comments
 (0)