Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_invalid_messages.py
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# 0. | # 0. | ||||
# | # | ||||
# Send as large a message as is valid, ensure we aren't disconnected but | # Send as large a message as is valid, ensure we aren't disconnected but | ||||
# also can't exhaust resources. | # also can't exhaust resources. | ||||
# | # | ||||
msg_at_size = msg_unrecognized("b" * valid_data_limit) | msg_at_size = msg_unrecognized("b" * valid_data_limit) | ||||
assert len(msg_at_size.serialize()) == msg_limit | assert len(msg_at_size.serialize()) == msg_limit | ||||
with node.assert_memory_usage_stable(perc_increase_allowed=0.03): | |||||
self.log.info( | self.log.info( | ||||
"Sending a bunch of large, junk messages to test " | "Sending a bunch of large, junk messages to test memory exhaustion. May take a bit...") | ||||
"memory exhaustion. May take a bit...") | |||||
# Run a bunch of times to test for memory exhaustion. | # Run a bunch of times to test for memory exhaustion. | ||||
for _ in range(80): | for _ in range(80): | ||||
node.p2p.send_message(msg_at_size) | node.p2p.send_message(msg_at_size) | ||||
# Check that, even though the node is being hammered by nonsense from one | # Check that, even though the node is being hammered by nonsense from one | ||||
# connection, it can still service other peers in a timely way. | # connection, it can still service other peers in a timely way. | ||||
for _ in range(20): | for _ in range(20): | ||||
conn2.sync_with_ping(timeout=2) | conn2.sync_with_ping(timeout=2) | ||||
# Peer 1, despite serving up a bunch of nonsense, should still be | # Peer 1, despite serving up a bunch of nonsense, should still be | ||||
# connected. | # connected. | ||||
self.log.info("Waiting for node to drop junk messages.") | self.log.info("Waiting for node to drop junk messages.") | ||||
node.p2p.sync_with_ping(timeout=30) | node.p2p.sync_with_ping(timeout=320) | ||||
assert node.p2p.is_connected | assert node.p2p.is_connected | ||||
# | # | ||||
# 1. | # 1. | ||||
# | # | ||||
# Send an oversized message, ensure we're disconnected. | # Send an oversized message, ensure we're disconnected. | ||||
# | # | ||||
msg_over_size = msg_unrecognized("b" * (valid_data_limit + 1)) | msg_over_size = msg_unrecognized("b" * (valid_data_limit + 1)) | ||||
assert len(msg_over_size.serialize()) == (msg_limit + 1) | assert len(msg_over_size.serialize()) == (msg_limit + 1) | ||||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |