Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Bug 838075 - mozprocess tests should clean up after themselves;r=wlach
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Hammel committed Mar 8, 2013
1 parent 9edbd3d commit 3a62843
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 192 deletions.
3 changes: 1 addition & 2 deletions mozprocess/tests/manifest.ini
@@ -1,2 +1 @@
[mozprocess1.py]
[mozprocess2.py]
[test_mozprocess.py]
157 changes: 0 additions & 157 deletions mozprocess/tests/mozprocess1.py

This file was deleted.

128 changes: 95 additions & 33 deletions mozprocess/tests/mozprocess2.py → mozprocess/tests/test_mozprocess.py 100755 → 100644
Expand Up @@ -14,11 +14,6 @@

here = os.path.dirname(os.path.abspath(__file__))

# This tests specifically the case reported in bug 671316
# TODO: Because of the way mutt works we can't just load a utils.py in here.
# so, for all process handler tests, copy these two
# utility functions to to the top of your source.

def make_proclaunch(aDir):
"""
Makes the proclaunch executable.
Expand All @@ -27,10 +22,10 @@ def make_proclaunch(aDir):
Returns:
the path to the proclaunch executable that is generated
"""
# Ideally make should take care of this, but since it doesn't - on windows,
# anyway, let's just call out both targets explicitly.
p = subprocess.call(["make", "-C", "iniparser"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=aDir)
p = subprocess.call(["make"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=aDir)
# Ideally make should take care of this, but since it doesn't,
# on windows anyway, let's just call out both targets explicitly.
p = subprocess.call(["make", "-C", "iniparser"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=aDir)
p = subprocess.call(["make"],stdout=subprocess.PIPE, stderr=subprocess.PIPE ,cwd=aDir)
if sys.platform == "win32":
exepath = os.path.join(aDir, "proclaunch.exe")
else:
Expand All @@ -39,12 +34,16 @@ def make_proclaunch(aDir):

def check_for_process(processName):
"""
Use to determine if process is still running.
Use to determine if process of the given name is still running.
Returns:
detected -- True if process is detected to exist, False otherwise
output -- if process exists, stdout of the process, '' otherwise
"""
# TODO: replace with
# https://github.com/mozilla/mozbase/blob/master/mozprocess/mozprocess/pid.py
# which should be augmented from talos
# see https://bugzilla.mozilla.org/show_bug.cgi?id=705864
output = ''
if sys.platform == "win32":
# On windows we use tasklist
Expand All @@ -70,22 +69,41 @@ def check_for_process(processName):

return detected, output

class ProcTest2(unittest.TestCase):

def __init__(self, *args, **kwargs):

# Ideally, I'd use setUpClass but that only exists in 2.7.
# So, we'll do this make step now.
self.proclaunch = make_proclaunch(here)
unittest.TestCase.__init__(self, *args, **kwargs)

def test_process_waitnotimeout(self):
""" Process is started, runs to completion before our wait times out
"""
p = processhandler.ProcessHandler([self.proclaunch,
"process_waittimeout_10s.ini"],
class ProcTest(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.proclaunch = make_proclaunch(here)

@classmethod
def tearDownClass(cls):
files = [('proclaunch',),
('proclaunch.exe',),
('iniparser', 'dictionary.o'),
('iniparser', 'iniparser.lib'),
('iniparser', 'iniparser.o'),
('iniparser', 'libiniparser.a'),
('iniparser', 'libiniparser.so.0'),
]
files = [os.path.join(here, *path) for path in files]
errors = []
for path in files:
if os.path.exists(path):
try:
os.remove(path)
except OSError as e:
errors.append(str(e))
if errors:
raise OSError("Error(s) encountered tearing down %s.%s:\n%s" % (cls.__module__, cls.__name__, '\n'.join(errors)))
del cls.proclaunch

def test_process_normal_finish(self):
"""Process is started, runs to completion while we wait for it"""

p = processhandler.ProcessHandler([self.proclaunch, "process_normal_finish.ini"],
cwd=here)
p.run(timeout=30)
p.run()
p.wait()

detected, output = check_for_process(self.proclaunch)
Expand All @@ -95,8 +113,7 @@ def test_process_waitnotimeout(self):
p.didTimeout)

def test_process_wait(self):
""" Process is started runs to completion while we wait indefinitely
"""
"""Process is started runs to completion while we wait indefinitely"""

p = processhandler.ProcessHandler([self.proclaunch,
"process_waittimeout_10s.ini"],
Expand All @@ -110,6 +127,23 @@ def test_process_wait(self):
p.proc.returncode,
p.didTimeout)

def test_process_timeout(self):
""" Process is started, runs but we time out waiting on it
to complete
"""
p = processhandler.ProcessHandler([self.proclaunch, "process_waittimeout.ini"],
cwd=here)
p.run(timeout=10)
p.wait()

detected, output = check_for_process(self.proclaunch)
self.determine_status(detected,
output,
p.proc.returncode,
p.didTimeout,
False,
['returncode', 'didtimeout'])

def test_process_waittimeout(self):
"""
Process is started, then wait is called and times out.
Expand All @@ -128,7 +162,36 @@ def test_process_waittimeout(self):
p.proc.returncode,
p.didTimeout,
True,
[])
())

def test_process_waitnotimeout(self):
""" Process is started, runs to completion before our wait times out
"""
p = processhandler.ProcessHandler([self.proclaunch,
"process_waittimeout_10s.ini"],
cwd=here)
p.run(timeout=30)
p.wait()

detected, output = check_for_process(self.proclaunch)
self.determine_status(detected,
output,
p.proc.returncode,
p.didTimeout)

def test_process_kill(self):
"""Process is started, we kill it"""

p = processhandler.ProcessHandler([self.proclaunch, "process_normal_finish.ini"],
cwd=here)
p.run()
p.kill()

detected, output = check_for_process(self.proclaunch)
self.determine_status(detected,
output,
p.proc.returncode,
p.didTimeout)

def test_process_output_twice(self):
"""
Expand All @@ -148,16 +211,15 @@ def test_process_output_twice(self):
p.proc.returncode,
p.didTimeout,
False,
[])

())

def determine_status(self,
detected=False,
output = '',
returncode = 0,
didtimeout = False,
output='',
returncode=0,
didtimeout=False,
isalive=False,
expectedfail=[]):
expectedfail=()):
"""
Use to determine if the situation has failed.
Parameters:
Expand Down

0 comments on commit 3a62843

Please sign in to comment.