diff options
| author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-05-04 01:33:23 +0200 |
|---|---|---|
| committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-05-04 01:33:23 +0200 |
| commit | 2e885e3ce4ccd0b87db9ad6398df71fca5c024fd (patch) | |
| tree | 1ca80ed22ce7d2b19fd598e3c3fee7aff6f6f3e2 | |
| parent | 200f5675b6fc4f0e82b09a7ea192087ab9c99ea4 (diff) | |
| download | psutil-2e885e3ce4ccd0b87db9ad6398df71fca5c024fd.tar.gz | |
port zombie test to namespaces
| -rw-r--r-- | psutil/tests/__init__.py | 11 | ||||
| -rwxr-xr-x | psutil/tests/test_process.py | 43 |
2 files changed, 18 insertions, 36 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index 5fb22e68..13867d1f 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -1002,6 +1002,15 @@ class TestMemoryLeak(PsutilTestCase): self.execute(call, **kwargs) +def _get_eligible_cpu(): + p = psutil.Process() + if hasattr(p, "cpu_num"): + return p.cpu_num() + elif hasattr(p, "cpu_affinity"): + return p.cpu_affinity()[0] + return 0 + + class process_namespace: """A container that lists all the method names of the Process class + some reasonable parameters to be called with. @@ -1086,7 +1095,7 @@ class process_namespace: else: setters += [('ionice', (psutil.IOPRIO_NORMAL, ), {})] if HAS_CPU_AFFINITY: - setters += [('cpu_affinity', ([0], ), {})] + setters += [('cpu_affinity', ([_get_eligible_cpu()], ), {})] killers = [ ('send_signal', (signal.SIGTERM, ), {}), diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 3f146b1c..2361acaf 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -1269,9 +1269,9 @@ class TestProcess(PsutilTestCase): @unittest.skipIf(not POSIX, 'POSIX only') def test_zombie_process(self): - def succeed_or_zombie_p_exc(fun, *args, **kwargs): + def succeed_or_zombie_p_exc(fun): try: - return fun(*args, **kwargs) + return fun() except (psutil.ZombieProcess, psutil.AccessDenied): pass @@ -1284,39 +1284,7 @@ class TestProcess(PsutilTestCase): assert zproc.is_running() # ...and as_dict() shouldn't crash zproc.as_dict() - - if hasattr(zproc, "rlimit"): - succeed_or_zombie_p_exc(zproc.rlimit, psutil.RLIMIT_NOFILE) - succeed_or_zombie_p_exc(zproc.rlimit, psutil.RLIMIT_NOFILE, - (5, 5)) - # set methods - succeed_or_zombie_p_exc(zproc.parent) - if hasattr(zproc, 'cpu_affinity'): - try: - succeed_or_zombie_p_exc(zproc.cpu_affinity, [0]) - except ValueError as err: - if TRAVIS and LINUX and "not eligible" in str(err): - # https://travis-ci.org/giampaolo/psutil/jobs/279890461 - pass - else: - raise - - succeed_or_zombie_p_exc(zproc.nice, 0) - if hasattr(zproc, 'ionice'): - if LINUX: - succeed_or_zombie_p_exc(zproc.ionice, 2, 0) - else: - succeed_or_zombie_p_exc(zproc.ionice, 0) # Windows - if hasattr(zproc, 'rlimit'): - succeed_or_zombie_p_exc(zproc.rlimit, - psutil.RLIMIT_NOFILE, (5, 5)) - succeed_or_zombie_p_exc(zproc.suspend) - succeed_or_zombie_p_exc(zproc.resume) - succeed_or_zombie_p_exc(zproc.terminate) - succeed_or_zombie_p_exc(zproc.kill) - - # ...its parent should 'see' it - # edit: not true on BSD and MACOS + # ...its parent should 'see' it (edit: not true on BSD and MACOS # descendants = [x.pid for x in psutil.Process().children( # recursive=True)] # self.assertIn(zpid, descendants) @@ -1325,6 +1293,11 @@ class TestProcess(PsutilTestCase): # rid of a zombie is to kill its parent. # self.assertEqual(zpid.ppid(), os.getpid()) # ...and all other APIs should be able to deal with it + + ns = process_namespace(zproc) + for fun, name in ns.iter(*ns.all): + succeed_or_zombie_p_exc(fun) + assert psutil.pid_exists(zproc.pid) if not TRAVIS and MACOS: # For some reason this started failing all of the sudden. |
