Skip to content

Commit b03562b

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 <rusty@rustcorp.com.au>
1 parent 6865fe3 commit b03562b

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
@@ -4719,3 +4719,23 @@ def test_openchannel_hook_channel_type(node_factory, bitcoind):
47194719
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'\]}")
47204720
else:
47214721
l2.daemon.wait_for_log(r"plugin-openchannel_hook_accepter.py: accept by design: channel_type {'bits': \[12\], 'names': \['static_remotekey/even'\]}")
4722+
4723+
4724+
@pytest.mark.slow_test
4725+
def test_spam_commands(node_factory, bitcoind):
4726+
plugin = os.path.join(os.getcwd(), "tests/plugins/test_libplugin")
4727+
l1 = node_factory.get_node(options={"plugin": plugin, 'log-level': 'info'},
4728+
start=False)
4729+
4730+
# Memleak detection here creates significant overhead!
4731+
del l1.daemon.env["LIGHTNINGD_DEV_MEMLEAK"]
4732+
# Don't bother recording all our io.
4733+
del l1.daemon.opts['dev-save-plugin-io']
4734+
l1.start()
4735+
4736+
start_time = time.time()
4737+
l1.rpc.spamcommand(1_000_000)
4738+
duration = time.time() - start_time
4739+
4740+
# Change 100 to 0 to get test to fail so you can see the result!
4741+
assert duration < 100

0 commit comments

Comments
 (0)