Skip to content

Commit f687009

Browse files
committed
pytest: make test_gossip_throttle more reliable.
By having gossipwith filter out messages we don't want, we can get the counts of expected messages correct, and not hit errors like this: ``` def test_gossip_throttle(node_factory, bitcoind, chainparams): """Make some gossip, test it gets throttled""" l1, l2, l3, l4 = node_factory.line_graph(4, wait_for_announce=True, opts=[{}, {}, {}, {'dev-throttle-gossip': None}]) # We expect: self-advertizement (3 messages for l1 and l4) plus # 4 node announcements, 3 channel announcements and 6 channel updates. # We also expect it to send a timestamp filter message. # (We won't take long enough to get a ping!) expected = 4 + 4 + 3 + 6 + 1 # l1 is unlimited start_fast = time.time() out1 = subprocess.run(['devtools/gossipwith', '--all-gossip', '--hex', '--network={}'.format(TEST_NETWORK), '--max-messages={}'.format(expected), '{}@localhost:{}'.format(l1.info['id'], l1.port)], check=True, timeout=TIMEOUT, stdout=subprocess.PIPE).stdout.split() time_fast = time.time() - start_fast assert time_fast < 2 # Remove timestamp filter, since timestamp will change! out1 = [m for m in out1 if not m.startswith(b'0109')] # l4 is throttled start_slow = time.time() out2 = subprocess.run(['devtools/gossipwith', '--all-gossip', '--hex', '--network={}'.format(TEST_NETWORK), '--max-messages={}'.format(expected), '{}@localhost:{}'.format(l4.info['id'], l4.port)], check=True, timeout=TIMEOUT, stdout=subprocess.PIPE).stdout.split() time_slow = time.time() - start_slow assert time_slow > 3 # Remove timestamp filter, since timestamp will change! out2 = [m for m in out2 if not m.startswith(b'0109')] # Contents should be identical (once uniquified, since each # doubles-up on its own gossip) > assert set(out1) == set(out2) E AssertionError: assert {b'010054b1907bdf639c9060e0fa4bca02419c46f75a99f0908b87a2e09711d5d031ba76b8fd07acc8be1b2fac9e31efb808e5d362c32ef4665... E Extra items in the left set: E b'01010ad5be8b9ba029245c2ae2d667af7ead7c0129c479c7fd7145a9b65931e90222082e6e4ab37ef60ebd10f1493d73e8bf7a40c4ae5f7d87cc...8488830b60f7e744ed9235eb0b1ba93283b315c035180266e44a554e494f524245414d2d333930353033622d6d6f64646564000000000000000000' E Extra items in the right set: E b'01079f87eb580b9e5f11dc211e9fb66abb3699999044f8fe146801162393364286c6000000010000006c010101' ``` Signed-off-by: Rusty Russell <[email protected]>
1 parent f771461 commit f687009

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

tests/test_gossip.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,41 +2058,36 @@ def test_gossip_throttle(node_factory, bitcoind, chainparams):
20582058

20592059
# We expect: self-advertizement (3 messages for l1 and l4) plus
20602060
# 4 node announcements, 3 channel announcements and 6 channel updates.
2061-
# We also expect it to send a timestamp filter message.
2062-
# (We won't take long enough to get a ping!)
2063-
expected = 4 + 4 + 3 + 6 + 1
2061+
expected = 4 + 4 + 3 + 6
20642062

20652063
# l1 is unlimited
20662064
start_fast = time.time()
20672065
out1 = subprocess.run(['devtools/gossipwith',
20682066
'--all-gossip',
20692067
'--hex',
20702068
'--network={}'.format(TEST_NETWORK),
2069+
'--filter=256,257,258',
20712070
'--max-messages={}'.format(expected),
20722071
'{}@localhost:{}'.format(l1.info['id'], l1.port)],
20732072
check=True,
20742073
timeout=TIMEOUT, stdout=subprocess.PIPE).stdout.split()
20752074
time_fast = time.time() - start_fast
20762075
assert time_fast < 2
2077-
# Remove timestamp filter, since timestamp will change!
2078-
out1 = [m for m in out1 if not m.startswith(b'0109')]
20792076

20802077
# l4 is throttled
20812078
start_slow = time.time()
20822079
out2 = subprocess.run(['devtools/gossipwith',
20832080
'--all-gossip',
20842081
'--hex',
20852082
'--network={}'.format(TEST_NETWORK),
2083+
'--filter=256,257,258',
20862084
'--max-messages={}'.format(expected),
20872085
'{}@localhost:{}'.format(l4.info['id'], l4.port)],
20882086
check=True,
20892087
timeout=TIMEOUT, stdout=subprocess.PIPE).stdout.split()
20902088
time_slow = time.time() - start_slow
20912089
assert time_slow > 3
20922090

2093-
# Remove timestamp filter, since timestamp will change!
2094-
out2 = [m for m in out2 if not m.startswith(b'0109')]
2095-
20962091
# Contents should be identical (once uniquified, since each
20972092
# doubles-up on its own gossip)
20982093
assert set(out1) == set(out2)
@@ -2121,30 +2116,29 @@ def test_gossip_throttle(node_factory, bitcoind, chainparams):
21212116
'--no-gossip',
21222117
'--hex',
21232118
'--network={}'.format(TEST_NETWORK),
2124-
'--max-messages={}'.format(expected + 1),
2119+
'--filter=256,257,258',
2120+
'--max-messages={}'.format(expected),
21252121
'{}@localhost:{}'.format(l1.info['id'], l1.port),
21262122
query],
21272123
check=True,
21282124
timeout=TIMEOUT, stdout=subprocess.PIPE).stdout.split()
21292125
time_fast = time.time() - start_fast
21302126
assert time_fast < 2
2131-
# Ignore gossip_timestamp_filter and reply_short_channel_ids_end
2132-
out3 = [m for m in out3 if not m.startswith(b'0109') and not m.startswith(b'0106')]
21332127
assert set(out1) == set(out3)
21342128

21352129
start_slow = time.time()
21362130
out4 = subprocess.run(['devtools/gossipwith',
21372131
'--no-gossip',
21382132
'--hex',
21392133
'--network={}'.format(TEST_NETWORK),
2134+
'--filter=256,257,258',
21402135
'--max-messages={}'.format(expected),
21412136
'{}@localhost:{}'.format(l4.info['id'], l4.port),
21422137
query],
21432138
check=True,
21442139
timeout=TIMEOUT, stdout=subprocess.PIPE).stdout.split()
21452140
time_slow = time.time() - start_slow
21462141
assert time_slow > 3
2147-
out4 = [m for m in out4 if not m.startswith(b'0109')]
21482142
assert set(out2) == set(out4)
21492143

21502144

0 commit comments

Comments
 (0)