|
1 #!/usr/bin/env python |
|
2 |
|
3 import os |
|
4 import time |
|
5 import unittest |
|
6 import proctest |
|
7 from mozprocess import processhandler |
|
8 |
|
9 here = os.path.dirname(os.path.abspath(__file__)) |
|
10 |
|
11 class ProcTestKill(proctest.ProcTest): |
|
12 """ Class to test various process tree killing scenatios """ |
|
13 |
|
14 def test_process_kill(self): |
|
15 """Process is started, we kill it""" |
|
16 |
|
17 p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_finish_python.ini"], |
|
18 cwd=here) |
|
19 p.run() |
|
20 p.kill() |
|
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 expectedfail=('returncode',)) |
|
28 |
|
29 def test_process_kill_deep(self): |
|
30 """Process is started, we kill it, we use a deep process tree""" |
|
31 |
|
32 p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_deep_python.ini"], |
|
33 cwd=here) |
|
34 p.run() |
|
35 p.kill() |
|
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 expectedfail=('returncode',)) |
|
43 |
|
44 def test_process_kill_deep_wait(self): |
|
45 """Process is started, we use a deep process tree, we let it spawn |
|
46 for a bit, we kill it""" |
|
47 |
|
48 p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_deep_python.ini"], |
|
49 cwd=here) |
|
50 p.run() |
|
51 # Let the tree spawn a bit, before attempting to kill |
|
52 time.sleep(3) |
|
53 p.kill() |
|
54 |
|
55 detected, output = proctest.check_for_process(self.proclaunch) |
|
56 self.determine_status(detected, |
|
57 output, |
|
58 p.proc.returncode, |
|
59 p.didTimeout, |
|
60 expectedfail=('returncode',)) |
|
61 |
|
62 def test_process_kill_broad(self): |
|
63 """Process is started, we kill it, we use a broad process tree""" |
|
64 |
|
65 p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_broad_python.ini"], |
|
66 cwd=here) |
|
67 p.run() |
|
68 p.kill() |
|
69 |
|
70 detected, output = proctest.check_for_process(self.proclaunch) |
|
71 self.determine_status(detected, |
|
72 output, |
|
73 p.proc.returncode, |
|
74 p.didTimeout, |
|
75 expectedfail=('returncode',)) |
|
76 |
|
77 if __name__ == '__main__': |
|
78 unittest.main() |