mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 1433905 - [mozprocess] Retrieving pid has to fail with RuntimeError if process hasn't been started yet. r=gbrown
Instead of an AttributeError a RuntimeError has to be thrown if the underlying process hasn't been created yet. Depends on D7392 Differential Revision: https://phabricator.services.mozilla.com/D7393 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
2141453224
commit
8744982dbc
@ -789,9 +789,9 @@ falling back to not using job objects for managing child processes""", file=sys.
|
||||
:param sig: Signal used to kill the process, defaults to SIGKILL
|
||||
(has no effect on Windows)
|
||||
"""
|
||||
if not hasattr(self, 'proc'):
|
||||
raise RuntimeError("Calling kill() on a non started process is not"
|
||||
" allowed.")
|
||||
if not hasattr(self, "proc"):
|
||||
raise RuntimeError("Process hasn't been started yet")
|
||||
|
||||
self.proc.kill(sig=sig)
|
||||
|
||||
# When we kill the the managed process we also have to wait for the
|
||||
@ -811,9 +811,9 @@ falling back to not using job objects for managing child processes""", file=sys.
|
||||
# Ensure that we first check for the reader status. Otherwise
|
||||
# we might mark the process as finished while output is still getting
|
||||
# processed.
|
||||
if not hasattr(self, 'proc'):
|
||||
raise RuntimeError("Calling poll() on a non started process is not"
|
||||
" allowed.")
|
||||
if not hasattr(self, "proc"):
|
||||
raise RuntimeError("Process hasn't been started yet")
|
||||
|
||||
elif self.reader.is_alive():
|
||||
return None
|
||||
elif hasattr(self.proc, "returncode"):
|
||||
@ -872,6 +872,9 @@ falling back to not using job objects for managing child processes""", file=sys.
|
||||
|
||||
@property
|
||||
def pid(self):
|
||||
if not hasattr(self, "proc"):
|
||||
raise RuntimeError("Process hasn't been started yet")
|
||||
|
||||
return self.proc.pid
|
||||
|
||||
@staticmethod
|
||||
|
@ -3,6 +3,7 @@ subsuite = mozbase, os == "linux"
|
||||
skip-if = python == 3
|
||||
[test_kill.py]
|
||||
[test_misc.py]
|
||||
[test_pid.py]
|
||||
[test_poll.py]
|
||||
[test_wait.py]
|
||||
[test_output.py]
|
||||
|
51
testing/mozbase/mozprocess/tests/test_pid.py
Normal file
51
testing/mozbase/mozprocess/tests/test_pid.py
Normal file
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
|
||||
import mozunit
|
||||
|
||||
from mozprocess import processhandler
|
||||
|
||||
import proctest
|
||||
|
||||
|
||||
here = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
class ProcTestPid(proctest.ProcTest):
|
||||
"""Class to test process pid."""
|
||||
|
||||
def test_pid_before_run(self):
|
||||
"""Process is not started, and pid is checked."""
|
||||
p = processhandler.ProcessHandler([self.python])
|
||||
with self.assertRaises(RuntimeError):
|
||||
p.pid
|
||||
|
||||
def test_pid_while_running(self):
|
||||
"""Process is started, and pid is checked."""
|
||||
p = processhandler.ProcessHandler([self.python, self.proclaunch,
|
||||
"process_normal_finish.ini"],
|
||||
cwd=here)
|
||||
p.run()
|
||||
|
||||
self.assertIsNotNone(p.pid)
|
||||
|
||||
self.determine_status(p, True)
|
||||
p.kill()
|
||||
|
||||
def test_pid_after_kill(self):
|
||||
"""Process is killed, and pid is checked."""
|
||||
p = processhandler.ProcessHandler([self.python, self.proclaunch,
|
||||
"process_normal_finish.ini"],
|
||||
cwd=here)
|
||||
p.run()
|
||||
p.kill()
|
||||
|
||||
self.assertIsNotNone(p.pid)
|
||||
self.determine_status(p)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
mozunit.main()
|
Loading…
Reference in New Issue
Block a user