Skip to content

Commit af3c8a7

Browse files
committed
Merge #14693: test_node: get_mem_rss fixups
fa9ed38 test_node: get_mem_rss fixups (MarcoFalke) Pull request description: Follow up to #14522: * Fix math (Memory usage increase relative to previous memory usage, not final memory usage) * remove `shell=True` * assert that the node is running * Make it work on BSD-like systems Tree-SHA512: fc1b4f88173914b6cb6373655cffd781044a0c146339e3fa90da03b197faa20954567a77335965b857d29d27f32661698b6a0340f0c616f643b8c4510cd360c2
2 parents 4822325 + fa9ed38 commit af3c8a7

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
@@ -118,22 +118,19 @@ def get_deterministic_priv_key(self):
118118
def get_mem_rss(self):
119119
"""Get the memory usage (RSS) per `ps`.
120120
121-
If process is stopped or `ps` is unavailable, return None.
121+
Returns None if `ps` is unavailable.
122122
"""
123-
if not (self.running and self.process):
124-
self.log.warning("Couldn't get memory usage; process isn't running.")
125-
return None
123+
assert self.running
126124

127125
try:
128126
return int(subprocess.check_output(
129-
"ps h -o rss {}".format(self.process.pid),
130-
shell=True, stderr=subprocess.DEVNULL).strip())
127+
["ps", "h", "-o", "rss", "{}".format(self.process.pid)],
128+
stderr=subprocess.DEVNULL).split()[-1])
131129

132-
# Catching `Exception` broadly to avoid failing on platforms where ps
133-
# isn't installed or doesn't work as expected, e.g. OpenBSD.
130+
# Avoid failing on platforms where ps isn't installed.
134131
#
135132
# We could later use something like `psutils` to work across platforms.
136-
except Exception:
133+
except (FileNotFoundError, subprocess.SubprocessError):
137134
self.log.exception("Unable to get memory usage")
138135
return None
139136

@@ -308,7 +305,7 @@ def assert_memory_usage_stable(self, perc_increase_allowed=0.03):
308305
self.log.warning("Unable to detect memory usage (RSS) - skipping memory check.")
309306
return
310307

311-
perc_increase_memory_usage = 1 - (float(before_memory_usage) / after_memory_usage)
308+
perc_increase_memory_usage = (after_memory_usage / before_memory_usage) - 1
312309

313310
if perc_increase_memory_usage > perc_increase_allowed:
314311
self._raise_assertion_error(

0 commit comments

Comments
 (0)