|
1 #!/usr/bin/env python |
|
2 |
|
3 import os |
|
4 import unittest |
|
5 import proctest |
|
6 import mozinfo |
|
7 from mozprocess import processhandler |
|
8 |
|
9 here = os.path.dirname(os.path.abspath(__file__)) |
|
10 |
|
11 class ProcTestWait(proctest.ProcTest): |
|
12 """ Class to test process waits and timeouts """ |
|
13 |
|
14 def test_normal_finish(self): |
|
15 """Process is started, runs to completion while we wait for it""" |
|
16 |
|
17 p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_finish_python.ini"], |
|
18 cwd=here) |
|
19 p.run() |
|
20 p.wait() |
|
21 |
|
22 detected, output = proctest.check_for_process(self.proclaunch) |
|
23 self.determine_status(detected, |
|
24 output, |
|
25 p.proc.returncode, |
|
26 p.didTimeout) |
|
27 |
|
28 def test_wait(self): |
|
29 """Process is started runs to completion while we wait indefinitely""" |
|
30 |
|
31 p = processhandler.ProcessHandler([self.python, self.proclaunch, |
|
32 "process_waittimeout_10s_python.ini"], |
|
33 cwd=here) |
|
34 p.run() |
|
35 p.wait() |
|
36 |
|
37 detected, output = proctest.check_for_process(self.proclaunch) |
|
38 self.determine_status(detected, |
|
39 output, |
|
40 p.proc.returncode, |
|
41 p.didTimeout) |
|
42 |
|
43 |
|
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() |
|
52 |
|
53 detected, output = proctest.check_for_process(self.proclaunch) |
|
54 |
|
55 if mozinfo.isUnix: |
|
56 # process was killed, so returncode should be negative |
|
57 self.assertLess(p.proc.returncode, 0) |
|
58 |
|
59 self.determine_status(detected, |
|
60 output, |
|
61 p.proc.returncode, |
|
62 p.didTimeout, |
|
63 False, |
|
64 ['returncode', 'didtimeout']) |
|
65 |
|
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) |
|
74 |
|
75 p.run() |
|
76 p.wait(timeout=5) |
|
77 |
|
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 ()) |
|
85 |
|
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() |
|
94 |
|
95 detected, output = proctest.check_for_process(self.proclaunch) |
|
96 self.determine_status(detected, |
|
97 output, |
|
98 p.proc.returncode, |
|
99 p.didTimeout) |
|
100 |
|
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() |
|
110 |
|
111 detected, output = proctest.check_for_process(self.proclaunch) |
|
112 self.determine_status(detected, |
|
113 output, |
|
114 returncode2, |
|
115 p.didTimeout) |
|
116 |
|
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') |
|
121 |
|
122 if __name__ == '__main__': |
|
123 unittest.main() |