Skip to content

Commit a4eaaa6

Browse files
author
MarcoFalke
committed
Merge #14812: qa: fix p2p_invalid_messages on macOS
5a1f576 qa: clean up assert_memory_usage_stable utility (James O'Beirne) 0cf1632 qa: fix p2p_invalid_messages on macOS (James O'Beirne) Pull request description: Infinite mea culpa for the number of problems with this test. This change bumps the acceptable RSS increase threshold from 3% to 50% when spamming the test node with junk 4MB messages. On [@MarcoFalke's macOS test build](https://travis-ci.org/MarcoFalke/btc_nightly) we see RSS grow ~14% from ~71MB to 81MB, so a 50% increase threshold should be more than sufficient to avoid spurious failures. Tree-SHA512: 150a7b88080fd883c7a5d0b9ffa470f61a97c4885fccc1a06fde6260aaef15640a7c1de7e89c581b245df7807d617ec3d86775330386ec5149ad567492fc5d31
2 parents b5c3d7a + 5a1f576 commit a4eaaa6

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

test/functional/p2p_invalid_messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def run_test(self):
6666
msg_at_size = msg_unrecognized("b" * valid_data_limit)
6767
assert len(msg_at_size.serialize()) == msg_limit
6868

69-
with node.assert_memory_usage_stable(perc_increase_allowed=0.03):
69+
with node.assert_memory_usage_stable(increase_allowed=0.5):
7070
self.log.info(
7171
"Sending a bunch of large, junk messages to test "
7272
"memory exhaustion. May take a bit...")

test/functional/test_framework/test_node.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def get_deterministic_priv_key(self):
115115
]
116116
return PRIV_KEYS[self.index]
117117

118-
def get_mem_rss(self):
118+
def get_mem_rss_kilobytes(self):
119119
"""Get the memory usage (RSS) per `ps`.
120120
121121
Returns None if `ps` is unavailable.
@@ -291,26 +291,30 @@ def assert_debug_log(self, expected_msgs):
291291
self._raise_assertion_error('Expected message "{}" does not partially match log:\n\n{}\n\n'.format(expected_msg, print_log))
292292

293293
@contextlib.contextmanager
294-
def assert_memory_usage_stable(self, perc_increase_allowed=0.03):
294+
def assert_memory_usage_stable(self, *, increase_allowed=0.03):
295295
"""Context manager that allows the user to assert that a node's memory usage (RSS)
296296
hasn't increased beyond some threshold percentage.
297+
298+
Args:
299+
increase_allowed (float): the fractional increase in memory allowed until failure;
300+
e.g. `0.12` for up to 12% increase allowed.
297301
"""
298-
before_memory_usage = self.get_mem_rss()
302+
before_memory_usage = self.get_mem_rss_kilobytes()
299303

300304
yield
301305

302-
after_memory_usage = self.get_mem_rss()
306+
after_memory_usage = self.get_mem_rss_kilobytes()
303307

304308
if not (before_memory_usage and after_memory_usage):
305309
self.log.warning("Unable to detect memory usage (RSS) - skipping memory check.")
306310
return
307311

308312
perc_increase_memory_usage = (after_memory_usage / before_memory_usage) - 1
309313

310-
if perc_increase_memory_usage > perc_increase_allowed:
314+
if perc_increase_memory_usage > increase_allowed:
311315
self._raise_assertion_error(
312316
"Memory usage increased over threshold of {:.3f}% from {} to {} ({:.3f}%)".format(
313-
perc_increase_allowed * 100, before_memory_usage, after_memory_usage,
317+
increase_allowed * 100, before_memory_usage, after_memory_usage,
314318
perc_increase_memory_usage * 100))
315319

316320
def assert_start_raises_init_error(self, extra_args=None, expected_msg=None, match=ErrorMatch.FULL_TEXT, *args, **kwargs):

0 commit comments

Comments
 (0)