Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the predicate used for the --kill-running-processes flag #405

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions osbenchmark/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ def run_subprocess_with_logging(command_line, header=None, level=logging.INFO, s

def is_benchmark_process(p):
cmdline = p.cmdline()
# On Linux, /proc/PID/status truncates the command name to 15 characters.
return p.name() == "opensearch-benchmark" or \
(p.name().lower().startswith("python") and
(len(cmdline) > 1 and
(cmdline[1] == "opensearch-benchmark" or
cmdline[1].endswith(os.path.sep + "opensearch-benchmark"))))
p.name() == "opensearch-benc" or \
(len(cmdline) > 1 and
os.path.basename(cmdline[0].lower()).startswith("python") and
os.path.basename(cmdline[1]) == "opensearch-benchmark")


def find_all_other_benchmark_processes():
Expand Down
4 changes: 4 additions & 0 deletions tests/utils/process_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def test_kills_only_benchmark_processes(self, process_iter):
random_python = ProcessTests.Process(103, "python3", ["/some/django/app"])
other_process = ProcessTests.Process(104, "init", ["/usr/sbin/init"])
benchmark_process_p = ProcessTests.Process(105, "python3", ["/usr/bin/python3", "~/.local/bin/opensearch-benchmark"])
# On Linux, the process name is truncated to 15 characters.
benchmark_process_l = ProcessTests.Process(106, "opensearch-benc", ["/usr/bin/python3", "~/.local/bin/osbenchmark"])
benchmark_process_e = ProcessTests.Process(107, "opensearch-benchmark", ["/usr/bin/python3", "~/.local/bin/opensearch-benchmark"])
benchmark_process_mac = ProcessTests.Process(108, "Python", ["/Python.app/Contents/MacOS/Python",
"~/.local/bin/opensearch-benchmark"])
Expand All @@ -139,6 +141,7 @@ def test_kills_only_benchmark_processes(self, process_iter):
random_python,
other_process,
benchmark_process_p,
benchmark_process_l,
benchmark_process_e,
benchmark_process_mac,
own_benchmark_process,
Expand All @@ -153,6 +156,7 @@ def test_kills_only_benchmark_processes(self, process_iter):
self.assertFalse(random_python.killed)
self.assertFalse(other_process.killed)
self.assertTrue(benchmark_process_p.killed)
self.assertTrue(benchmark_process_l.killed)
self.assertTrue(benchmark_process_e.killed)
self.assertTrue(benchmark_process_mac.killed)
self.assertFalse(own_benchmark_process.killed)
Expand Down
Loading