Skip to content

Commit fb2f4bd

Browse files
committed
pytest: move benchmark in test_connection.py to tests/benchmarks.py
Signed-off-by: Rusty Russell <[email protected]>
1 parent 1aa5bbc commit fb2f4bd

File tree

2 files changed

+35
-36
lines changed

2 files changed

+35
-36
lines changed

tests/benchmark.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from concurrent import futures
22
from fixtures import * # noqa: F401,F403
3+
from pyln.client import RpcError
34
from tqdm import tqdm
4-
from utils import (wait_for, TIMEOUT)
5+
from utils import (wait_for, TIMEOUT, only_one)
56

67

78
import os
@@ -228,3 +229,36 @@ def test_spam_listcommands(node_factory, bitcoind, benchmark):
228229

229230
# This calls "listinvoice" 100,000 times (which doesn't need a transaction commit)
230231
benchmark(l1.rpc.spamlistcommand, 100_000)
232+
233+
234+
def test_payment_speed(node_factory, benchmark):
235+
"""This makes sure we don't screw up nagle handling.
236+
237+
Normally:
238+
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
239+
test_payment_speed 16.3587 40.4925 27.4874 5.5512 27.7885 8.9291 9;0 36.3803 33 1
240+
241+
Without TCP_NODELAY:
242+
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
243+
test_payment_speed 153.7132 163.2027 158.6747 3.4059 158.5219 6.3745 3;0 6.3022 9 1
244+
"""
245+
l1 = get_bench_node(node_factory, extra_options={'commit-time': 0})
246+
l2 = get_bench_node(node_factory, extra_options={'commit-time': 0})
247+
248+
node_factory.join_nodes([l1, l2])
249+
250+
scid = only_one(l1.rpc.listpeerchannels()['channels'])['short_channel_id']
251+
routestep = {
252+
'amount_msat': 100,
253+
'id': l2.info['id'],
254+
'delay': 5,
255+
'channel': scid
256+
}
257+
258+
def onepay(l1, routestep):
259+
phash = random.randbytes(32).hex()
260+
l1.rpc.sendpay([routestep], phash)
261+
with pytest.raises(RpcError, match="WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS"):
262+
l1.rpc.waitsendpay(phash)
263+
264+
benchmark(onepay, l1, routestep)

tests/test_connection.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4579,41 +4579,6 @@ def test_no_delay(node_factory):
45794579
assert end < start + 100 * 0.5
45804580

45814581

4582-
@unittest.skipIf(os.getenv('TEST_BENCH', '0') == '0', "For profiling")
4583-
def test_bench(node_factory):
4584-
"""Is our Nagle disabling for critical messages working?"""
4585-
l1, l2 = node_factory.get_nodes(2, opts={'start': False,
4586-
'commit-time': 0})
4587-
4588-
# memleak detection plays havoc with profiles.
4589-
del l1.daemon.env["LIGHTNINGD_DEV_MEMLEAK"]
4590-
del l2.daemon.env["LIGHTNINGD_DEV_MEMLEAK"]
4591-
4592-
l1.start()
4593-
l2.start()
4594-
node_factory.join_nodes([l1, l2])
4595-
4596-
scid = only_one(l1.rpc.listpeerchannels()['channels'])['short_channel_id']
4597-
routestep = {
4598-
'amount_msat': 100,
4599-
'id': l2.info['id'],
4600-
'delay': 5,
4601-
'channel': scid
4602-
}
4603-
4604-
start = time.time()
4605-
# If we were stupid enough to leave Nagle enabled, this would add 200ms
4606-
# seconds delays each way!
4607-
for _ in range(1000):
4608-
phash = random.randbytes(32).hex()
4609-
l1.rpc.sendpay([routestep], phash)
4610-
with pytest.raises(RpcError, match="WIRE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS"):
4611-
l1.rpc.waitsendpay(phash)
4612-
end = time.time()
4613-
duration = end - start
4614-
assert duration == 0
4615-
4616-
46174582
def test_listpeerchannels_by_scid(node_factory):
46184583
l1, l2, l3 = node_factory.line_graph(3, announce_channels=False)
46194584

0 commit comments

Comments
 (0)