Skip to content

Commit

Permalink
Merge bitcoin#14812: qa: fix p2p_invalid_messages on macOS
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MarcoFalke committed Nov 26, 2018
2 parents b5c3d7a + 5a1f576 commit a4eaaa6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/functional/p2p_invalid_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def run_test(self):
msg_at_size = msg_unrecognized("b" * valid_data_limit)
assert len(msg_at_size.serialize()) == msg_limit

with node.assert_memory_usage_stable(perc_increase_allowed=0.03):
with node.assert_memory_usage_stable(increase_allowed=0.5):
self.log.info(
"Sending a bunch of large, junk messages to test "
"memory exhaustion. May take a bit...")
Expand Down
16 changes: 10 additions & 6 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def get_deterministic_priv_key(self):
]
return PRIV_KEYS[self.index]

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

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

yield

after_memory_usage = self.get_mem_rss()
after_memory_usage = self.get_mem_rss_kilobytes()

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

perc_increase_memory_usage = (after_memory_usage / before_memory_usage) - 1

if perc_increase_memory_usage > perc_increase_allowed:
if perc_increase_memory_usage > increase_allowed:
self._raise_assertion_error(
"Memory usage increased over threshold of {:.3f}% from {} to {} ({:.3f}%)".format(
perc_increase_allowed * 100, before_memory_usage, after_memory_usage,
increase_allowed * 100, before_memory_usage, after_memory_usage,
perc_increase_memory_usage * 100))

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

0 comments on commit a4eaaa6

Please sign in to comment.