def test_process_waitnotimeout(self): """ Process is started, runs to completion before our wait times out """ p = processhandler.ProcessHandler([ self.python, self.proclaunch, "process_waittimeout_10s_python.ini" ], cwd=here) p.run(timeout=30) p.wait() detected, output = proctest.check_for_process(self.proclaunch) self.determine_status(detected, output, p.proc.returncode, p.didTimeout)
def test_waittimeout(self): """ Process is started, then wait is called and times out. Process is still running and didn't timeout """ p = processhandler.ProcessHandler( [self.python, self.proclaunch, "process_waittimeout_10s.ini"], cwd=here) p.run() p.wait(timeout=0) self.determine_status(p, True, ())
def test_process_wait(self): """Process is started runs to completion while we wait indefinitely""" p = processhandler.ProcessHandler([ self.python, self.proclaunch, "process_waittimeout_10s_python.ini" ], cwd=here) p.run() p.wait() detected, output = proctest.check_for_process(self.proclaunch) self.determine_status(detected, output, p.proc.returncode, p.didTimeout)
def test_process_output_twice(self): """ Process is started, then processOutput is called a second time explicitly """ p = processhandler.ProcessHandler( [self.python, self.proclaunch, "process_waittimeout_10s.ini"], cwd=here) p.run() p.processOutput(timeout=5) p.wait() self.determine_status(p, False, ())
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_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() 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_kill_deep_wait(self): """Process is started, we use a deep process tree, we let it spawn for a bit, we kill it""" p = processhandler.ProcessHandler( [self.python, self.proclaunch, "process_normal_deep_python.ini"], cwd=here) p.run() # Let the tree spawn a bit, before attempting to kill time.sleep(3) p.kill() self.determine_status(p, expectedfail=('returncode', ))
def test_poll_while_running(self): """Process is started, and poll() is called""" p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_finish.ini"], cwd=here) p.run() returncode = p.poll() self.assertEqual(returncode, None) self.determine_status(p, True) p.kill()
def test_poll_after_kill(self): """Process is killed, and poll() is called""" p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_finish.ini"], cwd=here) p.run() returncode = p.kill() # We killed the process, so the returncode should be < 0 self.assertLess(returncode, 0) self.assertEqual(returncode, p.poll()) self.determine_status(p)
def test_process_output_nonewline(self): """ Process is started, outputs data with no newline """ p = processhandler.ProcessHandler( [self.python, os.path.join("scripts", "procnonewline.py")], cwd=here) p.run() p.processOutput(timeout=5) p.wait() self.determine_status(p, False, ())
def test_process_kill_broad(self): """Process is started, we kill it, we use a broad process tree""" p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_broad_python.ini"], cwd=here) p.run() p.kill() detected, output = proctest.check_for_process(self.proclaunch) self.determine_status(detected, output, p.proc.returncode, p.didTimeout, expectedfail=('returncode',))
def test_poll_while_running(self): """Process is started, and poll() is called""" p = processhandler.ProcessHandler( [self.python, self.proclaunch, "process_normal_finish_python.ini"], cwd=here) p.run() returncode = p.poll() self.assertEqual(returncode, None) detected, output = proctest.check_for_process(self.proclaunch) self.determine_status(detected, output, returncode, p.didTimeout, True) p.kill()
def test_process_output_twice(self): """ Process is started, then processOutput is called a second time explicitly """ p = processhandler.ProcessHandler( [self.proclaunch, "process_waittimeout_10s.ini"], cwd=here) p.run() p.processOutput(timeout=5) p.wait() detected, output = check_for_process(self.proclaunch) self.determine_status(detected, output, p.proc.returncode, p.didTimeout, False, ())
def test_process_waittimeout(self): """ Process is started, then wait is called and times out. Process is still running and didn't timeout """ p = processhandler.ProcessHandler( [self.proclaunch, "process_waittimeout_10s.ini"], cwd=here) p.run() p.wait(timeout=5) detected, output = check_for_process(self.proclaunch) self.determine_status(detected, output, p.proc.returncode, p.didTimeout, True, ())
def test_process_output_nonewline(self): """ Process is started, outputs data with no newline """ p = processhandler.ProcessHandler([self.python, "procnonewline.py"], cwd=here) p.run() p.processOutput(timeout=5) p.wait() detected, output = proctest.check_for_process("procnonewline.py") self.determine_status(detected, output, p.proc.returncode, p.didTimeout, False, ())
def test_timeout(self): """ Process is started, runs but we time out waiting on it to complete """ p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_waittimeout_python.ini"], cwd=here) p.run(timeout=10) p.wait() if mozinfo.isUnix: # process was killed, so returncode should be negative self.assertLess(p.proc.returncode, 0) self.determine_status(p, False, ['returncode', 'didtimeout'])
def test_poll_after_kill(self): """Process is killed, and poll() is called""" p = processhandler.ProcessHandler( [self.python, self.proclaunch, "process_normal_finish_python.ini"], cwd=here) p.run() returncode = p.kill() # We killed the process, so the returncode should be < 0 self.assertLess(returncode, 0) self.assertEqual(returncode, p.poll()) detected, output = proctest.check_for_process(self.proclaunch) self.determine_status(detected, output, returncode, p.didTimeout)
def test_check_for_detached_while_running_with_current_pid(self): """Process is started, and check for detached with original pid.""" p = processhandler.ProcessHandler( [self.python, self.proclaunch, "process_normal_finish.ini"], cwd=here ) p.run() orig_pid = p.pid p.check_for_detached(p.pid) self.assertEqual(p.pid, orig_pid) self.assertIsNone(p.proc.detached_pid) self.determine_status(p, True) p.kill()
def test_check_for_detached_after_kill(self): """Process is killed before checking for detached pid.""" p = processhandler.ProcessHandler( [self.python, self.proclaunch, "process_normal_finish.ini"], cwd=here ) p.run() p.kill() orig_pid = p.pid p.check_for_detached(p.pid) self.assertEqual(p.pid, orig_pid) self.assertIsNone(p.proc.detached_pid) self.determine_status(p)
def test_poll_after_external_kill(self): """Process is killed externally, and poll() is called""" p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_finish.ini"], cwd=here) p.run() os.kill(p.pid, signal.SIGTERM) returncode = p.wait() # We killed the process, so the returncode should be < 0 self.assertEqual(returncode, -signal.SIGTERM) self.assertEqual(returncode, p.poll()) self.determine_status(p)
def test_process_kill_deep_wait(self): """Process is started, we use a deep process tree, we let it spawn for a bit, we kill it""" p = processhandler.ProcessHandler( [self.python, self.proclaunch, "process_normal_deep_python.ini"], cwd=here) p.run() # Let the tree spawn a bit, before attempting to kill time.sleep(3) p.kill() detected, output = proctest.check_for_process(self.proclaunch) self.determine_status(detected, output, p.proc.returncode, p.didTimeout)
def test_wait_twice_after_kill(self): """Bug 968718: Process is started and stopped. wait() twice afterward.""" p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_waittimeout_python.ini"], cwd=here) p.run() p.kill() returncode1 = p.wait() returncode2 = p.wait() self.determine_status(p) self.assertLess(returncode2, 0, 'Negative returncode expected, got "%s"' % returncode2) self.assertEqual(returncode1, returncode2, 'Expected both returncodes of wait() to be equal')
def test_process_timeout_no_kill(self): """ Process is started, runs but we time out waiting on it to complete. Process should not be killed. """ p = None def timeout_handler(): self.assertEqual(p.proc.poll(), None) p.kill() p = processhandler.ProcessHandler([self.proclaunch, "process_waittimeout.ini"], cwd=here, onTimeout=(timeout_handler,), kill_on_timeout=False) p.run(timeout=1) p.wait() self.assertTrue(p.didTimeout) self.determine_status(p, False, ['returncode', 'didtimeout'])
def start_content_server(): content_server_location = os.environ.get('STANDALONE_SERVER') if content_server_location is None: content_server_location = os.path.join(os.path.dirname(__file__), "../../standalone") os.chdir(content_server_location) p = processhandler.ProcessHandler(CONTENT_SERVER_COMMAND, env=CONTENT_SERVER_ENV) p.run() # Give the content server time to start. import time output = p.output while not output: time.sleep(1) output = p.output return p
def test_poll_after_kill(self): """Process is killed, and poll() is called.""" p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_finish.ini"], cwd=here) p.run() returncode = p.kill() # We killed the process, so the returncode should be non-zero if mozinfo.isWin: self.assertGreater(returncode, 0, 'Positive returncode expected, got "%s"' % returncode) else: self.assertLess(returncode, 0, 'Negative returncode expected, got "%s"' % returncode) self.assertEqual(returncode, p.poll()) self.determine_status(p)
def start_content_server(): content_server_location = os.environ.get('STANDALONE_SERVER') if content_server_location is None: content_server_location = WORKING_DIR os.chdir(content_server_location) p = processhandler.ProcessHandler(CONTENT_SERVER_COMMAND, env=CONTENT_SERVER_ENV) p.run() # Give the content server time to start. import time output = p.output while not output: time.sleep(1) output = p.output return p
def test_poll_after_external_kill(self): """Process is killed externally, and poll() is called.""" p = processhandler.ProcessHandler([self.python, self.proclaunch, "process_normal_finish.ini"], cwd=here) p.run() os.kill(p.pid, signal.SIGTERM) returncode = p.wait() # We killed the process, so the returncode should be non-zero if mozinfo.isWin: self.assertEqual(returncode, signal.SIGTERM, 'Positive returncode expected, got "%s"' % returncode) else: self.assertEqual(returncode, -signal.SIGTERM, '%s expected, got "%s"' % (-signal.SIGTERM, returncode)) self.assertEqual(returncode, p.poll()) self.determine_status(p)
def test_process_kill_broad_delayed(self): """Process is started, we use a broad process tree, we let it spawn for a bit, we kill it""" myenv = None # On macosx1014, subprocess fails to find `six` when run with python3. # This ensures that subprocess first looks to sys.path to find `six`. # See https://bugzilla.mozilla.org/show_bug.cgi?id=1562083 if sys.platform == 'darwin' and sys.version_info[0] > 2: myenv = os.environ.copy() myenv['PYTHONPATH'] = ':'.join(sys.path) p = processhandler.ProcessHandler( [self.python, self.proclaunch, "process_normal_broad.ini"], cwd=here, env=myenv) p.run() # Let the tree spawn a bit, before attempting to kill time.sleep(3) p.kill() self.determine_status(p, expectedfail=('returncode', ))
def npm(*args, **kwargs): from mozprocess import processhandler env = None if kwargs.get("env"): env = os.environ.copy() env.update(kwargs["env"]) proc_kwargs = {} if "processOutputLine" in kwargs: proc_kwargs["processOutputLine"] = kwargs["processOutputLine"] p = processhandler.ProcessHandler(cmd="npm", args=list(args), cwd=kwargs.get("cwd"), env=env, **proc_kwargs) if not kwargs.get("wait", True): return p wait_proc(p, cmd="npm", exit_on_fail=kwargs.get("exit_on_fail", True)) return p.returncode