tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_detached.py (1748B)


      1 #!/usr/bin/env python
      2 
      3 import os
      4 
      5 import mozunit
      6 import proctest
      7 from mozprocess import processhandler
      8 
      9 here = os.path.dirname(os.path.abspath(__file__))
     10 
     11 
     12 class ProcTestDetached(proctest.ProcTest):
     13    """Class to test for detached processes."""
     14 
     15    def test_check_for_detached_before_run(self):
     16        """Process is not started yet when checked for detached."""
     17        p = processhandler.ProcessHandler(
     18            [self.python, self.proclaunch, "process_normal_finish.ini"], cwd=here
     19        )
     20 
     21        with self.assertRaises(RuntimeError):
     22            p.check_for_detached(1234)
     23 
     24    def test_check_for_detached_while_running_with_current_pid(self):
     25        """Process is started, and check for detached with original pid."""
     26        p = processhandler.ProcessHandler(
     27            [self.python, self.proclaunch, "process_normal_finish.ini"], cwd=here
     28        )
     29        p.run()
     30 
     31        orig_pid = p.pid
     32        p.check_for_detached(p.pid)
     33 
     34        self.assertEqual(p.pid, orig_pid)
     35        self.assertIsNone(p.proc.detached_pid)
     36 
     37        self.determine_status(p, True)
     38        p.kill()
     39 
     40    def test_check_for_detached_after_fork(self):
     41        """Process is started, and check for detached with new pid."""
     42        pass
     43 
     44    def test_check_for_detached_after_kill(self):
     45        """Process is killed before checking for detached pid."""
     46        p = processhandler.ProcessHandler(
     47            [self.python, self.proclaunch, "process_normal_finish.ini"], cwd=here
     48        )
     49        p.run()
     50        p.kill()
     51 
     52        orig_pid = p.pid
     53        p.check_for_detached(p.pid)
     54 
     55        self.assertEqual(p.pid, orig_pid)
     56        self.assertIsNone(p.proc.detached_pid)
     57 
     58        self.determine_status(p)
     59 
     60 
     61 if __name__ == "__main__":
     62    mozunit.main()