mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
Merge #17469: test: Remove fragile assert_memory_usage_stable
fac942ca57dce6cfa5655a3ac8664d6a051bc01f test: Remove fragile assert_memory_usage_stable (MarcoFalke)
Pull request description:
This test fails on arm64 and a fuzz tests seems inappropriate for the functional test suite anyway, so remove it.
Example failures:
* https://travis-ci.org/bitcoin/bitcoin/jobs/611497963#L14517
* https://travis-ci.org/MarcoFalke/bitcoin-core/jobs/611029104#L3876
ACKs for top commit:
jamesob:
ACK fac942ca57
Tree-SHA512: 3577e7ce5891d221cb798454589ba796ed0c06621a26351bb919c23bc6bb46aafcd0b11cb02bbfde64b74d67cb2950da44959a7ecdc436491a34e8b045c1ccf4
This commit is contained in:
parent
0a5587c2f7
commit
640616ff10
@ -4,7 +4,6 @@
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
"""Test node responses to invalid network messages."""
|
||||
import asyncio
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
|
||||
@ -66,27 +65,21 @@ class InvalidMessagesTest(BitcoinTestFramework):
|
||||
msg_at_size = msg_unrecognized(str_data="b" * valid_data_limit)
|
||||
assert len(msg_at_size.serialize()) == msg_limit
|
||||
|
||||
increase_allowed = 0.5
|
||||
if [s for s in os.environ.get("BITCOIN_CONFIG", "").split(" ") if "--with-sanitizers" in s and "address" in s]:
|
||||
increase_allowed = 3.5
|
||||
with node.assert_memory_usage_stable(increase_allowed=increase_allowed):
|
||||
self.log.info(
|
||||
"Sending a bunch of large, junk messages to test "
|
||||
"memory exhaustion. May take a bit...")
|
||||
self.log.info("Sending a bunch of large, junk messages to test memory exhaustion. May take a bit...")
|
||||
|
||||
# Run a bunch of times to test for memory exhaustion.
|
||||
for _ in range(80):
|
||||
node.p2p.send_message(msg_at_size)
|
||||
# Run a bunch of times to test for memory exhaustion.
|
||||
for _ in range(80):
|
||||
node.p2p.send_message(msg_at_size)
|
||||
|
||||
# Check that, even though the node is being hammered by nonsense from one
|
||||
# connection, it can still service other peers in a timely way.
|
||||
for _ in range(20):
|
||||
conn2.sync_with_ping(timeout=2)
|
||||
# Check that, even though the node is being hammered by nonsense from one
|
||||
# connection, it can still service other peers in a timely way.
|
||||
for _ in range(20):
|
||||
conn2.sync_with_ping(timeout=2)
|
||||
|
||||
# Peer 1, despite serving up a bunch of nonsense, should still be connected.
|
||||
self.log.info("Waiting for node to drop junk messages.")
|
||||
node.p2p.sync_with_ping(timeout=320)
|
||||
assert node.p2p.is_connected
|
||||
# Peer 1, despite serving up a bunch of nonsense, should still be connected.
|
||||
self.log.info("Waiting for node to drop junk messages.")
|
||||
node.p2p.sync_with_ping(timeout=320)
|
||||
assert node.p2p.is_connected
|
||||
|
||||
#
|
||||
# 1.
|
||||
|
@ -148,28 +148,6 @@ class TestNode():
|
||||
]
|
||||
return PRIV_KEYS[self.index]
|
||||
|
||||
def get_mem_rss_kilobytes(self):
|
||||
"""Get the memory usage (RSS) per `ps`.
|
||||
|
||||
If process is stopped or `ps` is unavailable, return None.
|
||||
"""
|
||||
if not (self.running and self.process):
|
||||
self.log.warning("Couldn't get memory usage; process isn't running.")
|
||||
return None
|
||||
|
||||
try:
|
||||
return int(subprocess.check_output(
|
||||
"ps h -o rss {}".format(self.process.pid),
|
||||
shell=True, stderr=subprocess.DEVNULL).strip())
|
||||
|
||||
# Catching `Exception` broadly to avoid failing on platforms where ps
|
||||
# isn't installed or doesn't work as expected, e.g. OpenBSD.
|
||||
#
|
||||
# We could later use something like `psutils` to work across platforms.
|
||||
except Exception:
|
||||
self.log.exception("Unable to get memory usage")
|
||||
return None
|
||||
|
||||
def _node_msg(self, msg: str) -> str:
|
||||
"""Return a modified msg that identifies this node by its index as a debugging aid."""
|
||||
return "[node %d] %s" % (self.index, msg)
|
||||
@ -358,33 +336,6 @@ class TestNode():
|
||||
time.sleep(0.05)
|
||||
self._raise_assertion_error('Expected messages "{}" does not partially match log:\n\n{}\n\n'.format(str(expected_msgs), print_log))
|
||||
|
||||
@contextlib.contextmanager
|
||||
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_kilobytes()
|
||||
|
||||
yield
|
||||
|
||||
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 = 1 - (float(before_memory_usage) / after_memory_usage)
|
||||
|
||||
if perc_increase_memory_usage > increase_allowed:
|
||||
self._raise_assertion_error(
|
||||
"Memory usage increased over threshold of {:.3f}% from {} to {} ({:.3f}%)".format(
|
||||
increase_allowed * 100, before_memory_usage, after_memory_usage,
|
||||
perc_increase_memory_usage * 100))
|
||||
|
||||
@contextlib.contextmanager
|
||||
def profile_with_perf(self, profile_name):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user