mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 00:43:07 +02:00
Unittest - Allow specifying custom timeout for slow commands.
* Useful when testing with big tasks (1000+ annotations) or sync operations that take longer than 1 second (default)
This commit is contained in:
parent
b236e78f2e
commit
bb060d5ff8
2 changed files with 25 additions and 9 deletions
|
@ -46,6 +46,9 @@ def binary_location(cmd):
|
|||
def wait_process(proc, timeout=1):
|
||||
"""Wait for process to finish
|
||||
"""
|
||||
if timeout is None:
|
||||
timeout = 1
|
||||
|
||||
sleeptime = .1
|
||||
# Max number of attempts until giving up
|
||||
tries = int(timeout / sleeptime)
|
||||
|
@ -62,7 +65,7 @@ def wait_process(proc, timeout=1):
|
|||
return exit
|
||||
|
||||
|
||||
def _get_output(proc, input):
|
||||
def _get_output(proc, input, timeout=None):
|
||||
"""Collect output from the subprocess without blocking the main process if
|
||||
subprocess hangs.
|
||||
"""
|
||||
|
@ -84,7 +87,7 @@ def _get_output(proc, input):
|
|||
t.start()
|
||||
|
||||
# A task process shouldn't take longer than 1 second to finish
|
||||
exit = wait_process(proc)
|
||||
exit = wait_process(proc, timeout)
|
||||
|
||||
# If it does take longer than 1 second, abort it
|
||||
if exit is None:
|
||||
|
@ -113,7 +116,7 @@ def _get_output(proc, input):
|
|||
|
||||
|
||||
def run_cmd_wait(cmd, input=None, stdout=PIPE, stderr=PIPE,
|
||||
merge_streams=False, env=os.environ):
|
||||
merge_streams=False, env=os.environ, timeout=None):
|
||||
"Run a subprocess and wait for it to finish"
|
||||
|
||||
if input is None:
|
||||
|
@ -128,7 +131,7 @@ def run_cmd_wait(cmd, input=None, stdout=PIPE, stderr=PIPE,
|
|||
|
||||
p = Popen(cmd, stdin=stdin, stdout=stdout, stderr=stderr, bufsize=1,
|
||||
close_fds=ON_POSIX, env=env)
|
||||
out, err, exit = _get_output(p, input)
|
||||
out, err, exit = _get_output(p, input, timeout)
|
||||
|
||||
if exit != 0:
|
||||
raise CommandError(cmd, exit, out, err)
|
||||
|
@ -276,6 +279,7 @@ except ImportError:
|
|||
return name
|
||||
return None
|
||||
|
||||
|
||||
def parse_datafile(file):
|
||||
"""Parse .data files on the client and server treating files as JSON
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue