Bug 1433905 - [mozprocess] pid has to be None if no process exists yet.
MozReview-Commit-ID: 9nXxygfCfpG
--- a/testing/mozbase/mozprocess/mozprocess/processhandler.py
+++ b/testing/mozbase/mozprocess/mozprocess/processhandler.py
@@ -866,17 +866,20 @@ falling back to not using job objects fo
# TODO Remove this method when consumers have been fixed
def waitForFinish(self, timeout=None):
print("MOZPROCESS WARNING: ProcessHandler.waitForFinish() is deprecated, "
"use ProcessHandler.wait() instead", file=sys.stderr)
return self.wait(timeout=timeout)
@property
def pid(self):
- return self.proc.pid
+ if hasattr(self, "proc"):
+ return self.proc.pid
+ else:
+ return None
@staticmethod
def pid_exists(pid):
if pid < 0:
return False
if isWin:
try:
--- a/testing/mozbase/mozprocess/tests/manifest.ini
+++ b/testing/mozbase/mozprocess/tests/manifest.ini
@@ -2,11 +2,12 @@
subsuite = mozbase, os == "linux"
[test_detached.py]
skip-if = os == "win"
[test_kill.py]
[test_misc.py]
[test_output.py]
[test_params.py]
+[test_pid.py]
[test_poll.py]
[test_process_reader.py]
[test_wait.py]
new file mode 100644
--- /dev/null
+++ b/testing/mozbase/mozprocess/tests/test_pid.py
@@ -0,0 +1,53 @@
+#!/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 called"""
+
+ p = processhandler.ProcessHandler([self.python])
+ self.assertIsNone(p.pid)
+
+ def test_pid_while_running(self):
+ """Process is started, and pid is called"""
+
+ 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 called"""
+
+ 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()