diff options
author | MarcoFalke <falke.marco@gmail.com> | 2018-11-08 17:33:15 -0500 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2018-11-08 18:05:09 -0500 |
commit | fa9ed38d57042c8a69699903a546c7bc0c10aaff (patch) | |
tree | 1de7172101118c7a56064a17109c120201369aac /test/functional | |
parent | 11e1ac3ae08535cefbd8235a8deb6cd100bcb2b1 (diff) |
test_node: get_mem_rss fixups
Diffstat (limited to 'test/functional')
-rwxr-xr-x | test/functional/test_framework/test_node.py | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index ffff81e070..9dcc0e6d0e 100755 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -118,22 +118,19 @@ class TestNode(): def get_mem_rss(self): """Get the memory usage (RSS) per `ps`. - If process is stopped or `ps` is unavailable, return None. + Returns None if `ps` is unavailable. """ - if not (self.running and self.process): - self.log.warning("Couldn't get memory usage; process isn't running.") - return None + assert self.running try: return int(subprocess.check_output( - "ps h -o rss {}".format(self.process.pid), - shell=True, stderr=subprocess.DEVNULL).strip()) + ["ps", "h", "-o", "rss", "{}".format(self.process.pid)], + stderr=subprocess.DEVNULL).split()[-1]) - # Catching `Exception` broadly to avoid failing on platforms where ps - # isn't installed or doesn't work as expected, e.g. OpenBSD. + # Avoid failing on platforms where ps isn't installed. # # We could later use something like `psutils` to work across platforms. - except Exception: + except (FileNotFoundError, subprocess.SubprocessError): self.log.exception("Unable to get memory usage") return None @@ -308,7 +305,7 @@ class TestNode(): 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) + perc_increase_memory_usage = (after_memory_usage / before_memory_usage) - 1 if perc_increase_memory_usage > perc_increase_allowed: self._raise_assertion_error( |