Skip to content

Commit 8aaf7e1

Browse files
MarcoFalkefurszy
authored andcommitted
test: Remove fragile assert_memory_usage_stable
1 parent f68e22c commit 8aaf7e1

File tree

2 files changed

+12
-62
lines changed

2 files changed

+12
-62
lines changed

test/functional/p2p_invalid_messages.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test node responses to invalid network messages."""
66
import asyncio
7-
import os
87
import struct
98
import sys
109

@@ -66,24 +65,21 @@ def run_test(self):
6665
msg_at_size = msg_unrecognized(str_data="b" * valid_data_limit)
6766
assert len(msg_at_size.serialize()) == msg_limit
6867

69-
with node.assert_memory_usage_stable(increase_allowed=0.5):
70-
self.log.info(
71-
"Sending a bunch of large, junk messages to test "
72-
"memory exhaustion. May take a bit...")
68+
self.log.info("Sending a bunch of large, junk messages to test memory exhaustion. May take a bit...")
7369

74-
# Run a bunch of times to test for memory exhaustion.
75-
for _ in range(80):
76-
node.p2p.send_message(msg_at_size)
70+
# Run a bunch of times to test for memory exhaustion.
71+
for _ in range(80):
72+
node.p2p.send_message(msg_at_size)
7773

78-
# Check that, even though the node is being hammered by nonsense from one
79-
# connection, it can still service other peers in a timely way.
80-
for _ in range(20):
81-
conn2.sync_with_ping(timeout=2)
74+
# Check that, even though the node is being hammered by nonsense from one
75+
# connection, it can still service other peers in a timely way.
76+
for _ in range(20):
77+
conn2.sync_with_ping(timeout=2)
8278

83-
# Peer 1, despite serving up a bunch of nonsense, should still be connected.
84-
self.log.info("Waiting for node to drop junk messages.")
85-
node.p2p.sync_with_ping(timeout=320)
86-
assert node.p2p.is_connected
79+
# Peer 1, despite serving up a bunch of nonsense, should still be connected.
80+
self.log.info("Waiting for node to drop junk messages.")
81+
node.p2p.sync_with_ping(timeout=320)
82+
assert node.p2p.is_connected
8783

8884
#
8985
# 1.

test/functional/test_framework/test_node.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,6 @@ def __init__(self, i, dirname, extra_args, rpchost, timewait, binary, stderr, mo
8282

8383
self.p2ps = []
8484

85-
def get_mem_rss_kilobytes(self):
86-
"""Get the memory usage (RSS) per `ps`.
87-
88-
Returns None if `ps` is unavailable.
89-
"""
90-
assert self.running
91-
92-
try:
93-
return int(subprocess.check_output(
94-
["ps", "h", "-o", "rss", "{}".format(self.process.pid)],
95-
stderr=subprocess.DEVNULL).split()[-1])
96-
97-
# Avoid failing on platforms where ps isn't installed.
98-
#
99-
# We could later use something like `psutils` to work across platforms.
100-
except (FileNotFoundError, subprocess.SubprocessError):
101-
self.log.exception("Unable to get memory usage")
102-
return None
103-
10485
def __del__(self):
10586
# Ensure that we don't leave any bitcoind processes lying around after
10687
# the test ends
@@ -245,33 +226,6 @@ def assert_debug_log(self, expected_msgs):
245226
if re.search(re.escape(expected_msg), log, flags=re.MULTILINE) is None:
246227
raise AssertionError('Expected message "{}" does not partially match log:\n\n{}\n\n'.format(expected_msg, print_log))
247228

248-
@contextlib.contextmanager
249-
def assert_memory_usage_stable(self, *, increase_allowed=0.03):
250-
"""Context manager that allows the user to assert that a node's memory usage (RSS)
251-
hasn't increased beyond some threshold percentage.
252-
253-
Args:
254-
increase_allowed (float): the fractional increase in memory allowed until failure;
255-
e.g. `0.12` for up to 12% increase allowed.
256-
"""
257-
before_memory_usage = self.get_mem_rss_kilobytes()
258-
259-
yield
260-
261-
after_memory_usage = self.get_mem_rss_kilobytes()
262-
263-
if not (before_memory_usage and after_memory_usage):
264-
self.log.warning("Unable to detect memory usage (RSS) - skipping memory check.")
265-
return
266-
267-
perc_increase_memory_usage = (after_memory_usage / before_memory_usage) - 1
268-
269-
if perc_increase_memory_usage > increase_allowed:
270-
raise AssertionError(
271-
"Memory usage increased over threshold of {:.3f}% from {} to {} ({:.3f}%)".format(
272-
increase_allowed * 100, before_memory_usage, after_memory_usage,
273-
perc_increase_memory_usage * 100))
274-
275229
def node_encrypt_wallet(self, passphrase):
276230
""""Encrypts the wallet.
277231

0 commit comments

Comments
 (0)