Skip to content

Commit 0edfce5

Browse files
MarcoFalkefurszy
authored andcommitted
test_node: get_mem_rss fixups
1 parent 6f21213 commit 0edfce5

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

test/functional/test_framework/test_node.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,19 @@ def __init__(self, i, dirname, extra_args, rpchost, timewait, binary, stderr, mo
8484
def get_mem_rss(self):
8585
"""Get the memory usage (RSS) per `ps`.
8686
87-
If process is stopped or `ps` is unavailable, return None.
87+
Returns None if `ps` is unavailable.
8888
"""
89-
if not (self.running and self.process):
90-
self.log.warning("Couldn't get memory usage; process isn't running.")
91-
return None
89+
assert self.running
9290

9391
try:
9492
return int(subprocess.check_output(
95-
"ps h -o rss {}".format(self.process.pid),
96-
shell=True, stderr=subprocess.DEVNULL).strip())
93+
["ps", "h", "-o", "rss", "{}".format(self.process.pid)],
94+
stderr=subprocess.DEVNULL).split()[-1])
9795

98-
# Catching `Exception` broadly to avoid failing on platforms where ps
99-
# isn't installed or doesn't work as expected, e.g. OpenBSD.
96+
# Avoid failing on platforms where ps isn't installed.
10097
#
10198
# We could later use something like `psutils` to work across platforms.
102-
except Exception:
99+
except (FileNotFoundError, subprocess.SubprocessError):
103100
self.log.exception("Unable to get memory usage")
104101
return None
105102

@@ -262,7 +259,7 @@ def assert_memory_usage_stable(self, perc_increase_allowed=0.03):
262259
self.log.warning("Unable to detect memory usage (RSS) - skipping memory check.")
263260
return
264261

265-
perc_increase_memory_usage = 1 - (float(before_memory_usage) / after_memory_usage)
262+
perc_increase_memory_usage = (after_memory_usage / before_memory_usage) - 1
266263

267264
if perc_increase_memory_usage > perc_increase_allowed:
268265
raise AssertionError(

0 commit comments

Comments
 (0)