testing/mozbase/mozprocess/tests/test_mozprocess_wait.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 unittest
michael@0 5 import proctest
michael@0 6 import mozinfo
michael@0 7 from mozprocess import processhandler
michael@0 8
michael@0 9 here = os.path.dirname(os.path.abspath(__file__))
michael@0 10
michael@0 11 class ProcTestWait(proctest.ProcTest):
michael@0 12 """ Class to test process waits and timeouts """
michael@0 13
michael@0 14 def test_normal_finish(self):
michael@0 15 """Process is started, runs to completion while we wait for it"""
michael@0 16
michael@0 17 p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_finish_python.ini"],
michael@0 18 cwd=here)
michael@0 19 p.run()
michael@0 20 p.wait()
michael@0 21
michael@0 22 detected, output = proctest.check_for_process(self.proclaunch)
michael@0 23 self.determine_status(detected,
michael@0 24 output,
michael@0 25 p.proc.returncode,
michael@0 26 p.didTimeout)
michael@0 27
michael@0 28 def test_wait(self):
michael@0 29 """Process is started runs to completion while we wait indefinitely"""
michael@0 30
michael@0 31 p = processhandler.ProcessHandler([self.python, self.proclaunch,
michael@0 32 "process_waittimeout_10s_python.ini"],
michael@0 33 cwd=here)
michael@0 34 p.run()
michael@0 35 p.wait()
michael@0 36
michael@0 37 detected, output = proctest.check_for_process(self.proclaunch)
michael@0 38 self.determine_status(detected,
michael@0 39 output,
michael@0 40 p.proc.returncode,
michael@0 41 p.didTimeout)
michael@0 42
michael@0 43
michael@0 44 def test_timeout(self):
michael@0 45 """ Process is started, runs but we time out waiting on it
michael@0 46 to complete
michael@0 47 """
michael@0 48 p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_waittimeout_python.ini"],
michael@0 49 cwd=here)
michael@0 50 p.run(timeout=10)
michael@0 51 p.wait()
michael@0 52
michael@0 53 detected, output = proctest.check_for_process(self.proclaunch)
michael@0 54
michael@0 55 if mozinfo.isUnix:
michael@0 56 # process was killed, so returncode should be negative
michael@0 57 self.assertLess(p.proc.returncode, 0)
michael@0 58
michael@0 59 self.determine_status(detected,
michael@0 60 output,
michael@0 61 p.proc.returncode,
michael@0 62 p.didTimeout,
michael@0 63 False,
michael@0 64 ['returncode', 'didtimeout'])
michael@0 65
michael@0 66 def test_waittimeout(self):
michael@0 67 """
michael@0 68 Process is started, then wait is called and times out.
michael@0 69 Process is still running and didn't timeout
michael@0 70 """
michael@0 71 p = processhandler.ProcessHandler([self.python, self.proclaunch,
michael@0 72 "process_waittimeout_10s_python.ini"],
michael@0 73 cwd=here)
michael@0 74
michael@0 75 p.run()
michael@0 76 p.wait(timeout=5)
michael@0 77
michael@0 78 detected, output = proctest.check_for_process(self.proclaunch)
michael@0 79 self.determine_status(detected,
michael@0 80 output,
michael@0 81 p.proc.returncode,
michael@0 82 p.didTimeout,
michael@0 83 True,
michael@0 84 ())
michael@0 85
michael@0 86 def test_waitnotimeout(self):
michael@0 87 """ Process is started, runs to completion before our wait times out
michael@0 88 """
michael@0 89 p = processhandler.ProcessHandler([self.python, self.proclaunch,
michael@0 90 "process_waittimeout_10s_python.ini"],
michael@0 91 cwd=here)
michael@0 92 p.run(timeout=30)
michael@0 93 p.wait()
michael@0 94
michael@0 95 detected, output = proctest.check_for_process(self.proclaunch)
michael@0 96 self.determine_status(detected,
michael@0 97 output,
michael@0 98 p.proc.returncode,
michael@0 99 p.didTimeout)
michael@0 100
michael@0 101 def test_wait_twice_after_kill(self):
michael@0 102 """Bug 968718: Process is started and stopped. wait() twice afterward."""
michael@0 103 p = processhandler.ProcessHandler([self.python, self.proclaunch,
michael@0 104 "process_waittimeout_python.ini"],
michael@0 105 cwd=here)
michael@0 106 p.run()
michael@0 107 p.kill()
michael@0 108 returncode1 = p.wait()
michael@0 109 returncode2 = p.wait()
michael@0 110
michael@0 111 detected, output = proctest.check_for_process(self.proclaunch)
michael@0 112 self.determine_status(detected,
michael@0 113 output,
michael@0 114 returncode2,
michael@0 115 p.didTimeout)
michael@0 116
michael@0 117 self.assertLess(returncode2, 0,
michael@0 118 'Negative returncode expected, got "%s"' % returncode2)
michael@0 119 self.assertEqual(returncode1, returncode2,
michael@0 120 'Expected both returncodes of wait() to be equal')
michael@0 121
michael@0 122 if __name__ == '__main__':
michael@0 123 unittest.main()

mercurial