testing/mozbase/mozprocess/tests/test_mozprocess_poll.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/usr/bin/env python
michael@0 2
michael@0 3 import os
michael@0 4 import signal
michael@0 5 import unittest
michael@0 6
michael@0 7 import mozinfo
michael@0 8 from mozprocess import processhandler
michael@0 9
michael@0 10 import proctest
michael@0 11
michael@0 12
michael@0 13 here = os.path.dirname(os.path.abspath(__file__))
michael@0 14
michael@0 15
michael@0 16 class ProcTestPoll(proctest.ProcTest):
michael@0 17 """ Class to test process poll """
michael@0 18
michael@0 19 def test_poll_before_run(self):
michael@0 20 """Process is not started, and poll() is called"""
michael@0 21
michael@0 22 p = processhandler.ProcessHandler([self.python, self.proclaunch,
michael@0 23 "process_normal_finish_python.ini"],
michael@0 24 cwd=here)
michael@0 25 self.assertRaises(AttributeError, p.poll)
michael@0 26
michael@0 27 def test_poll_while_running(self):
michael@0 28 """Process is started, and poll() is called"""
michael@0 29
michael@0 30 p = processhandler.ProcessHandler([self.python, self.proclaunch,
michael@0 31 "process_normal_finish_python.ini"],
michael@0 32 cwd=here)
michael@0 33 p.run()
michael@0 34 returncode = p.poll()
michael@0 35
michael@0 36 self.assertEqual(returncode, None)
michael@0 37
michael@0 38 detected, output = proctest.check_for_process(self.proclaunch)
michael@0 39 self.determine_status(detected,
michael@0 40 output,
michael@0 41 returncode,
michael@0 42 p.didTimeout,
michael@0 43 True)
michael@0 44 p.kill()
michael@0 45
michael@0 46 def test_poll_after_kill(self):
michael@0 47 """Process is killed, and poll() is called"""
michael@0 48
michael@0 49 p = processhandler.ProcessHandler([self.python, self.proclaunch,
michael@0 50 "process_normal_finish_python.ini"],
michael@0 51 cwd=here)
michael@0 52 p.run()
michael@0 53 returncode = p.kill()
michael@0 54
michael@0 55 # We killed the process, so the returncode should be < 0
michael@0 56 self.assertLess(returncode, 0)
michael@0 57 self.assertEqual(returncode, p.poll())
michael@0 58
michael@0 59 detected, output = proctest.check_for_process(self.proclaunch)
michael@0 60 self.determine_status(detected,
michael@0 61 output,
michael@0 62 returncode,
michael@0 63 p.didTimeout)
michael@0 64
michael@0 65 def test_poll_after_kill_no_process_group(self):
michael@0 66 """Process (no group) is killed, and poll() is called"""
michael@0 67
michael@0 68 p = processhandler.ProcessHandler([self.python, self.proclaunch,
michael@0 69 "process_normal_finish_no_process_group.ini"],
michael@0 70 cwd=here,
michael@0 71 ignore_children=True
michael@0 72 )
michael@0 73 p.run()
michael@0 74 returncode = p.kill()
michael@0 75
michael@0 76 # We killed the process, so the returncode should be < 0
michael@0 77 self.assertLess(returncode, 0)
michael@0 78 self.assertEqual(returncode, p.poll())
michael@0 79
michael@0 80 detected, output = proctest.check_for_process(self.proclaunch)
michael@0 81 self.determine_status(detected,
michael@0 82 output,
michael@0 83 returncode,
michael@0 84 p.didTimeout)
michael@0 85
michael@0 86 def test_poll_after_double_kill(self):
michael@0 87 """Process is killed twice, and poll() is called"""
michael@0 88
michael@0 89 p = processhandler.ProcessHandler([self.python, self.proclaunch,
michael@0 90 "process_normal_finish_python.ini"],
michael@0 91 cwd=here)
michael@0 92 p.run()
michael@0 93 p.kill()
michael@0 94 returncode = p.kill()
michael@0 95
michael@0 96 # We killed the process, so the returncode should be < 0
michael@0 97 self.assertLess(returncode, 0)
michael@0 98 self.assertEqual(returncode, p.poll())
michael@0 99
michael@0 100 detected, output = proctest.check_for_process(self.proclaunch)
michael@0 101 self.determine_status(detected,
michael@0 102 output,
michael@0 103 returncode,
michael@0 104 p.didTimeout)
michael@0 105
michael@0 106 def test_poll_after_external_kill(self):
michael@0 107 """Process is killed externally, and poll() is called"""
michael@0 108
michael@0 109 p = processhandler.ProcessHandler([self.python, self.proclaunch,
michael@0 110 "process_normal_finish_python.ini"],
michael@0 111 cwd=here)
michael@0 112 p.run()
michael@0 113 os.kill(p.pid, signal.SIGTERM)
michael@0 114 returncode = p.wait()
michael@0 115
michael@0 116 # We killed the process, so the returncode should be < 0
michael@0 117 self.assertEqual(returncode, -signal.SIGTERM)
michael@0 118 self.assertEqual(returncode, p.poll())
michael@0 119
michael@0 120 detected, output = proctest.check_for_process(self.proclaunch)
michael@0 121 self.determine_status(detected,
michael@0 122 output,
michael@0 123 returncode,
michael@0 124 p.didTimeout)
michael@0 125
michael@0 126 if __name__ == '__main__':
michael@0 127 unittest.main()

mercurial