Bug 1433905 - [mozprocess] check_for_detached has to return early if proc doesn't exist. draft
authorHenrik Skupin <mail@hskupin.info>
Tue, 29 May 2018 15:57:09 +0200
changeset 801032 6fbb9b91e5456d7041392b527190c1e128a1f004
parent 800404 db78be8dbc1c81844eb7d35c1a3073078eb5d923
child 801033 a4691a7badc2db905f443af6d8d72a796926ce1b
push id111546
push userbmo:hskupin@gmail.com
push dateTue, 29 May 2018 16:17:28 +0000
bugs1433905
milestone62.0a1
Bug 1433905 - [mozprocess] check_for_detached has to return early if proc doesn't exist. MozReview-Commit-ID: Lty4OFfT3m9
testing/mozbase/mozprocess/mozprocess/processhandler.py
testing/mozbase/mozprocess/tests/manifest.ini
testing/mozbase/mozprocess/tests/test_detached.py
--- a/testing/mozbase/mozprocess/mozprocess/processhandler.py
+++ b/testing/mozbase/mozprocess/mozprocess/processhandler.py
@@ -918,17 +918,17 @@ falling back to not using job objects fo
 
         In case of application restarts the process can spawn itself into a new process group.
         From now on the process can no longer be tracked by mozprocess anymore and has to be
         marked as detached. If the consumer of mozprocess still knows the new process id it could
         check for the detached state.
 
         new_pid is the new process id of the child process.
         """
-        if not self.proc:
+        if not hasattr(self, "proc"):
             return
 
         if isPosix:
             new_pgid = self._getpgid(new_pid)
 
             if new_pgid and new_pgid != self.proc.pgid:
                 self.proc.detached_pid = new_pid
                 print('Child process with id "%s" has been marked as detached because it is no '
--- a/testing/mozbase/mozprocess/tests/manifest.ini
+++ b/testing/mozbase/mozprocess/tests/manifest.ini
@@ -1,10 +1,12 @@
 [DEFAULT]
 subsuite = mozbase, os == "linux"
 
+[test_detached.py]
+skip-if = os == "win"
 [test_kill.py]
 [test_misc.py]
-[test_poll.py]
-[test_wait.py]
 [test_output.py]
 [test_params.py]
+[test_poll.py]
 [test_process_reader.py]
+[test_wait.py]
new file mode 100644
--- /dev/null
+++ b/testing/mozbase/mozprocess/tests/test_detached.py
@@ -0,0 +1,56 @@
+#!/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 ProcTestDetached(proctest.ProcTest):
+    """ Class to test process detached """
+
+    def test_check_for_detached_while_running_with_current_pid(self):
+        """Process is started, and poll() is called"""
+
+        p = processhandler.ProcessHandler([self.python, self.proclaunch,
+                                           "process_normal_finish.ini"],
+                                          cwd=here)
+        p.run()
+
+        orig_pid = p.pid
+        p.check_for_detached(p.pid)
+
+        self.assertEqual(p.pid, orig_pid)
+        self.assertIsNone(p.proc.detached_pid)
+
+        self.determine_status(p, True)
+        p.kill()
+
+    def test_check_for_detached_after_kill(self):
+        """Process is killed, and poll() is called"""
+
+        p = processhandler.ProcessHandler([self.python, self.proclaunch,
+                                           "process_normal_finish.ini"],
+                                          cwd=here)
+        p.run()
+        p.kill()
+
+        orig_pid = p.pid
+        p.check_for_detached(p.pid)
+
+        self.assertEqual(p.pid, orig_pid)
+        self.assertIsNone(p.proc.detached_pid)
+
+        self.determine_status(p)
+
+
+if __name__ == '__main__':
+    mozunit.main()