michael@0: #!/usr/bin/env python michael@0: michael@0: import os michael@0: import time michael@0: import unittest michael@0: import proctest michael@0: from mozprocess import processhandler michael@0: michael@0: here = os.path.dirname(os.path.abspath(__file__)) michael@0: michael@0: class ProcTestKill(proctest.ProcTest): michael@0: """ Class to test various process tree killing scenatios """ michael@0: michael@0: def test_process_kill(self): michael@0: """Process is started, we kill it""" michael@0: michael@0: p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_finish_python.ini"], michael@0: cwd=here) michael@0: p.run() michael@0: p.kill() michael@0: michael@0: detected, output = proctest.check_for_process(self.proclaunch) michael@0: self.determine_status(detected, michael@0: output, michael@0: p.proc.returncode, michael@0: p.didTimeout, michael@0: expectedfail=('returncode',)) michael@0: michael@0: def test_process_kill_deep(self): michael@0: """Process is started, we kill it, we use a deep process tree""" michael@0: michael@0: p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_deep_python.ini"], michael@0: cwd=here) michael@0: p.run() michael@0: p.kill() michael@0: michael@0: detected, output = proctest.check_for_process(self.proclaunch) michael@0: self.determine_status(detected, michael@0: output, michael@0: p.proc.returncode, michael@0: p.didTimeout, michael@0: expectedfail=('returncode',)) michael@0: michael@0: def test_process_kill_deep_wait(self): michael@0: """Process is started, we use a deep process tree, we let it spawn michael@0: for a bit, we kill it""" michael@0: michael@0: p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_deep_python.ini"], michael@0: cwd=here) michael@0: p.run() michael@0: # Let the tree spawn a bit, before attempting to kill michael@0: time.sleep(3) michael@0: p.kill() michael@0: michael@0: detected, output = proctest.check_for_process(self.proclaunch) michael@0: self.determine_status(detected, michael@0: output, michael@0: p.proc.returncode, michael@0: p.didTimeout, michael@0: expectedfail=('returncode',)) michael@0: michael@0: def test_process_kill_broad(self): michael@0: """Process is started, we kill it, we use a broad process tree""" michael@0: michael@0: p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_broad_python.ini"], michael@0: cwd=here) michael@0: p.run() michael@0: p.kill() michael@0: michael@0: detected, output = proctest.check_for_process(self.proclaunch) michael@0: self.determine_status(detected, michael@0: output, michael@0: p.proc.returncode, michael@0: p.didTimeout, michael@0: expectedfail=('returncode',)) michael@0: michael@0: if __name__ == '__main__': michael@0: unittest.main()