Allow timeout on test cases
Certain commands are likely to fail to terminate in case something goes wrong. Having the ability to force such commands to terminate after a certain time is useful.
This commit is contained in:
@ -407,7 +407,7 @@ class TestCase:
|
|||||||
with open(tgt_file, "w", encoding=tgt_encoding) as f:
|
with open(tgt_file, "w", encoding=tgt_encoding) as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
|
||||||
def cmd(self, cmdline):
|
def cmd(self, cmdline, timeout=None):
|
||||||
tmpdir = self.__tmpdir
|
tmpdir = self.__tmpdir
|
||||||
before = tmpdir.snapshot()
|
before = tmpdir.snapshot()
|
||||||
stdout_log = tmpdir.stdout_log()
|
stdout_log = tmpdir.stdout_log()
|
||||||
@ -417,7 +417,7 @@ class TestCase:
|
|||||||
print("### cmdline:", cmdline)
|
print("### cmdline:", cmdline)
|
||||||
with open(stdout_log, "w") as stdout, open(stderr_log, "w") as stderr:
|
with open(stdout_log, "w") as stdout, open(stderr_log, "w") as stderr:
|
||||||
if cmdline:
|
if cmdline:
|
||||||
err = subprocess.call(cmdline, stdout=stdout, stderr=stderr, shell=True)
|
err = subprocess.call(cmdline, stdout=stdout, stderr=stderr, shell=True, timeout=timeout)
|
||||||
else:
|
else:
|
||||||
err = 0
|
err = 0
|
||||||
after = tmpdir.snapshot()
|
after = tmpdir.snapshot()
|
||||||
|
Reference in New Issue
Block a user