Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Commit

Permalink
Fix straggler usage of legacy psutil form
Browse files Browse the repository at this point in the history
- Fix straggler usage of legacy psutil property form in pidlock.py.
- Add a simple test case to exercise the psutil dependency to catch this in CI in the future.

Testing Done:
https://travis-ci.org/pantsbuild/pants/builds/73467865

with the new test, pre-fix:

[illuminati pants (kwlzn/psutil_fixup)]$ PANTS_DEV=1 ./pants test tests/python/pants_test/process::
...
15:36:02 00:00     [pytest]
15:36:02 00:00       [run]
                     ============== test session starts ===============
                     platform darwin -- Python 2.7.6 -- py-1.4.30 -- pytest-2.6.4
                     plugins: timeout, cov
                     collected 9 items

                     tests/python/pants_test/process/test_pidlock.py F
                     tests/python/pants_test/process/test_xargs.py ........

                     ==================== FAILURES ====================
                      TestOwnerPrintingPIDLockFile.test_cmdline_for_pid

                     self = <pants_test.process.test_pidlock.TestOwnerPrintingPIDLockFile testMethod=test_cmdline_for_pid>

                         def test_cmdline_for_pid(self):
                     >     self.assertIsInstance(self.obj.cmdline_for_pid(os.getpid()))

                     tests/python/pants_test/process/test_pidlock.py:19:
                     _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

                     pid = 82357

                         @staticmethod
                         def cmdline_for_pid(pid):
                           try:
                             process = psutil.Process(pid)
                     >       return ' '.join(process.cmdline)
                     E       TypeError

                     src/python/pants/process/pidlock.py:38: TypeError
                     ======= 1 failed, 8 passed in 0.05 seconds =======
...
FAILURE

and with the fix:

[illuminati pants (kwlzn/psutil_fixup)]$ PANTS_DEV=1 ./pants test tests/python/pants_test/process::
...
15:38:41 00:00     [pytest]
15:38:41 00:00       [run]
                     ============== test session starts ===============
                     platform darwin -- Python 2.7.6 -- py-1.4.30 -- pytest-2.6.4
                     plugins: timeout, cov
                     collected 9 items

                     tests/python/pants_test/process/test_pidlock.py .
                     tests/python/pants_test/process/test_xargs.py ........

                     ============ 9 passed in 0.04 seconds ============
...
               SUCCESS

Bugs closed: 1889

Reviewed at https://rbcommons.com/s/twitter/r/2546/
  • Loading branch information
kwlzn authored and jsirois committed Jul 31, 2015
1 parent 461bb39 commit ae71f44
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/python/pants/process/pidlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ def acquire(self, timeout=None):
def cmdline_for_pid(pid):
try:
process = psutil.Process(pid)
return ' '.join(process.cmdline)
return ' '.join(process.cmdline())
except psutil.NoSuchProcess:
return None
1 change: 1 addition & 0 deletions tests/python/pants_test/process/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ python_tests(
sources = globs('*.py'),
dependencies = [
'3rdparty/python:mox',
'3rdparty/python:six',
'src/python/pants/process',
]
)
21 changes: 21 additions & 0 deletions tests/python/pants_test/process/test_pidlock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# coding=utf-8
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import os
import unittest

import six

from pants.process.pidlock import OwnerPrintingPIDLockFile


class TestOwnerPrintingPIDLockFile(unittest.TestCase):
def setUp(self):
self.obj = OwnerPrintingPIDLockFile('/tmp/test', False)

def test_cmdline_for_pid(self):
self.assertIsInstance(self.obj.cmdline_for_pid(os.getpid()), six.string_types)

0 comments on commit ae71f44

Please sign in to comment.