testing/mozbase/mozprocess/tests/test_mozprocess_wait.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mozbase/mozprocess/tests/test_mozprocess_wait.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,123 @@
     1.4 +#!/usr/bin/env python
     1.5 +
     1.6 +import os
     1.7 +import unittest
     1.8 +import proctest
     1.9 +import mozinfo
    1.10 +from mozprocess import processhandler
    1.11 +
    1.12 +here = os.path.dirname(os.path.abspath(__file__))
    1.13 +
    1.14 +class ProcTestWait(proctest.ProcTest):
    1.15 +    """ Class to test process waits and timeouts """
    1.16 +
    1.17 +    def test_normal_finish(self):
    1.18 +        """Process is started, runs to completion while we wait for it"""
    1.19 +
    1.20 +        p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_finish_python.ini"],
    1.21 +                                          cwd=here)
    1.22 +        p.run()
    1.23 +        p.wait()
    1.24 +
    1.25 +        detected, output = proctest.check_for_process(self.proclaunch)
    1.26 +        self.determine_status(detected,
    1.27 +                              output,
    1.28 +                              p.proc.returncode,
    1.29 +                              p.didTimeout)
    1.30 +
    1.31 +    def test_wait(self):
    1.32 +        """Process is started runs to completion while we wait indefinitely"""
    1.33 +
    1.34 +        p = processhandler.ProcessHandler([self.python, self.proclaunch,
    1.35 +                                          "process_waittimeout_10s_python.ini"],
    1.36 +                                          cwd=here)
    1.37 +        p.run()
    1.38 +        p.wait()
    1.39 +
    1.40 +        detected, output = proctest.check_for_process(self.proclaunch)
    1.41 +        self.determine_status(detected,
    1.42 +                              output,
    1.43 +                              p.proc.returncode,
    1.44 +                              p.didTimeout)
    1.45 +
    1.46 +
    1.47 +    def test_timeout(self):
    1.48 +        """ Process is started, runs but we time out waiting on it
    1.49 +            to complete
    1.50 +        """
    1.51 +        p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_waittimeout_python.ini"],
    1.52 +                                          cwd=here)
    1.53 +        p.run(timeout=10)
    1.54 +        p.wait()
    1.55 +
    1.56 +        detected, output = proctest.check_for_process(self.proclaunch)
    1.57 +
    1.58 +        if mozinfo.isUnix:
    1.59 +            # process was killed, so returncode should be negative
    1.60 +            self.assertLess(p.proc.returncode, 0)
    1.61 +
    1.62 +        self.determine_status(detected,
    1.63 +                              output,
    1.64 +                              p.proc.returncode,
    1.65 +                              p.didTimeout,
    1.66 +                              False,
    1.67 +                              ['returncode', 'didtimeout'])
    1.68 +
    1.69 +    def test_waittimeout(self):
    1.70 +        """
    1.71 +        Process is started, then wait is called and times out.
    1.72 +        Process is still running and didn't timeout
    1.73 +        """
    1.74 +        p = processhandler.ProcessHandler([self.python, self.proclaunch,
    1.75 +                                          "process_waittimeout_10s_python.ini"],
    1.76 +                                          cwd=here)
    1.77 +
    1.78 +        p.run()
    1.79 +        p.wait(timeout=5)
    1.80 +
    1.81 +        detected, output = proctest.check_for_process(self.proclaunch)
    1.82 +        self.determine_status(detected,
    1.83 +                              output,
    1.84 +                              p.proc.returncode,
    1.85 +                              p.didTimeout,
    1.86 +                              True,
    1.87 +                              ())
    1.88 +
    1.89 +    def test_waitnotimeout(self):
    1.90 +        """ Process is started, runs to completion before our wait times out
    1.91 +        """
    1.92 +        p = processhandler.ProcessHandler([self.python, self.proclaunch,
    1.93 +                                          "process_waittimeout_10s_python.ini"],
    1.94 +                                          cwd=here)
    1.95 +        p.run(timeout=30)
    1.96 +        p.wait()
    1.97 +
    1.98 +        detected, output = proctest.check_for_process(self.proclaunch)
    1.99 +        self.determine_status(detected,
   1.100 +                              output,
   1.101 +                              p.proc.returncode,
   1.102 +                              p.didTimeout)
   1.103 +
   1.104 +    def test_wait_twice_after_kill(self):
   1.105 +        """Bug 968718: Process is started and stopped. wait() twice afterward."""
   1.106 +        p = processhandler.ProcessHandler([self.python, self.proclaunch,
   1.107 +                                          "process_waittimeout_python.ini"],
   1.108 +                                          cwd=here)
   1.109 +        p.run()
   1.110 +        p.kill()
   1.111 +        returncode1 = p.wait()
   1.112 +        returncode2 = p.wait()
   1.113 +
   1.114 +        detected, output = proctest.check_for_process(self.proclaunch)
   1.115 +        self.determine_status(detected,
   1.116 +                              output,
   1.117 +                              returncode2,
   1.118 +                              p.didTimeout)
   1.119 +
   1.120 +        self.assertLess(returncode2, 0,
   1.121 +                        'Negative returncode expected, got "%s"' % returncode2)
   1.122 +        self.assertEqual(returncode1, returncode2,
   1.123 +                         'Expected both returncodes of wait() to be equal')
   1.124 +
   1.125 +if __name__ == '__main__':
   1.126 +    unittest.main()

mercurial