Skip to content

Commit

Permalink
Remove psutil and any code that depends on it
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannguyen4 committed Jan 4, 2024
1 parent 96152d2 commit 792576d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 74 deletions.
72 changes: 0 additions & 72 deletions test/new_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,84 +4,12 @@
import sys

import pytest
from _pytest.terminal import TerminalReporter # noqa: F401
from collections import namedtuple
from itertools import groupby
import tracemalloc

from . import invalid_data
from .test_base_class import TestBaseClass

aerospike = pytest.importorskip("aerospike")

test_memleak = int(os.environ.get("TEST_MEMLEAK", 0))

if test_memleak == 1:
from psutil import Process

_proc = Process(os.getpid())

LEAK_LIMIT = 0

def get_consumed_ram():
return _proc.memory_info().rss

START = "START"
END = "END"
ConsumedRamLogEntry = namedtuple("ConsumedRamLogEntry", ("nodeid", "on", "consumed_ram"))
consumed_ram_log = []
ConsumedTracemallocLogEntry = namedtuple("ConsumedTracemallocLogEntry", ("nodeid", "on", "consumed_tracemalloc"))
consumed_tracemalloc_log = []

tracemalloc.start(10)
snapshot1 = []
snapshot2 = []

@pytest.hookimpl(hookwrapper=True)
def pytest_terminal_summary(terminalreporter): # type: (TerminalReporter) -> generator # noqa: F821
yield

# you can do here anything - I just print report info
print("*" * 8 + "HERE CUSTOM LOGIC" + "*" * 8)

for failed in terminalreporter.stats.get("failed", []): # type: TestReport # noqa: F821
print("failed! node_id:%s, duration: %s" % (failed.nodeid, failed.duration))

for passed in terminalreporter.stats.get("passed", []): # type: TestReport # noqa: F821
print(
"passed! node_id:%s, duration: %s, details: %s" % (passed.nodeid, passed.duration, str(passed.longrepr))
)

grouped = groupby(consumed_ram_log, lambda entry: entry.nodeid)
for nodeid, (start_entry, end_entry) in grouped:
leaked = end_entry.consumed_ram - start_entry.consumed_ram
if leaked > LEAK_LIMIT:
terminalreporter.write("LEAKED {}KB in {}\n".format(leaked / 1024, nodeid))

tmgrouped = groupby(consumed_tracemalloc_log, lambda entry: entry.nodeid)
for nodeid, (start_entry, end_entry) in tmgrouped:
stats = end_entry.consumed_tracemalloc.compare_to(start_entry.consumed_tracemalloc, "lineno")
print(f"{nodeid}:")
for stat in stats[:3]:
print(stat)
# terminalreporter.write(stats)

def pytest_runtest_setup(item):

log_entry = ConsumedRamLogEntry(item.nodeid, START, get_consumed_ram())
consumed_ram_log.append(log_entry)

tmlog_entry = ConsumedTracemallocLogEntry(item.nodeid, START, tracemalloc.take_snapshot())
consumed_tracemalloc_log.append(tmlog_entry)

def pytest_runtest_teardown(item):

log_entry = ConsumedRamLogEntry(item.nodeid, END, get_consumed_ram())
consumed_ram_log.append(log_entry)

tmlog_entry = ConsumedTracemallocLogEntry(item.nodeid, END, tracemalloc.take_snapshot())
consumed_tracemalloc_log.append(tmlog_entry)


# Comment this out because nowhere in the repository is using it
'''
Expand Down
2 changes: 0 additions & 2 deletions test/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ pytest==7.4.0
pytest-cov==4.1.0
# Memory profiling
pytest-memray==1.5.0
# TODO: these should be removed since we are not using them
psutil

0 comments on commit 792576d

Please sign in to comment.