Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 #!/usr/bin/env python
3 import os
4 import unittest
5 import proctest
6 import mozinfo
7 from mozprocess import processhandler
9 here = os.path.dirname(os.path.abspath(__file__))
11 class ProcTestWait(proctest.ProcTest):
12 """ Class to test process waits and timeouts """
14 def test_normal_finish(self):
15 """Process is started, runs to completion while we wait for it"""
17 p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_finish_python.ini"],
18 cwd=here)
19 p.run()
20 p.wait()
22 detected, output = proctest.check_for_process(self.proclaunch)
23 self.determine_status(detected,
24 output,
25 p.proc.returncode,
26 p.didTimeout)
28 def test_wait(self):
29 """Process is started runs to completion while we wait indefinitely"""
31 p = processhandler.ProcessHandler([self.python, self.proclaunch,
32 "process_waittimeout_10s_python.ini"],
33 cwd=here)
34 p.run()
35 p.wait()
37 detected, output = proctest.check_for_process(self.proclaunch)
38 self.determine_status(detected,
39 output,
40 p.proc.returncode,
41 p.didTimeout)
44 def test_timeout(self):
45 """ Process is started, runs but we time out waiting on it
46 to complete
47 """
48 p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_waittimeout_python.ini"],
49 cwd=here)
50 p.run(timeout=10)
51 p.wait()
53 detected, output = proctest.check_for_process(self.proclaunch)
55 if mozinfo.isUnix:
56 # process was killed, so returncode should be negative
57 self.assertLess(p.proc.returncode, 0)
59 self.determine_status(detected,
60 output,
61 p.proc.returncode,
62 p.didTimeout,
63 False,
64 ['returncode', 'didtimeout'])
66 def test_waittimeout(self):
67 """
68 Process is started, then wait is called and times out.
69 Process is still running and didn't timeout
70 """
71 p = processhandler.ProcessHandler([self.python, self.proclaunch,
72 "process_waittimeout_10s_python.ini"],
73 cwd=here)
75 p.run()
76 p.wait(timeout=5)
78 detected, output = proctest.check_for_process(self.proclaunch)
79 self.determine_status(detected,
80 output,
81 p.proc.returncode,
82 p.didTimeout,
83 True,
84 ())
86 def test_waitnotimeout(self):
87 """ Process is started, runs to completion before our wait times out
88 """
89 p = processhandler.ProcessHandler([self.python, self.proclaunch,
90 "process_waittimeout_10s_python.ini"],
91 cwd=here)
92 p.run(timeout=30)
93 p.wait()
95 detected, output = proctest.check_for_process(self.proclaunch)
96 self.determine_status(detected,
97 output,
98 p.proc.returncode,
99 p.didTimeout)
101 def test_wait_twice_after_kill(self):
102 """Bug 968718: Process is started and stopped. wait() twice afterward."""
103 p = processhandler.ProcessHandler([self.python, self.proclaunch,
104 "process_waittimeout_python.ini"],
105 cwd=here)
106 p.run()
107 p.kill()
108 returncode1 = p.wait()
109 returncode2 = p.wait()
111 detected, output = proctest.check_for_process(self.proclaunch)
112 self.determine_status(detected,
113 output,
114 returncode2,
115 p.didTimeout)
117 self.assertLess(returncode2, 0,
118 'Negative returncode expected, got "%s"' % returncode2)
119 self.assertEqual(returncode1, returncode2,
120 'Expected both returncodes of wait() to be equal')
122 if __name__ == '__main__':
123 unittest.main()