Introduce option to define timeout for time-consuming file operations

Signed-off-by: Robert Baldyga <robert.baldyga@huawei.com>
This commit is contained in:
Robert Baldyga
2024-10-02 21:52:08 +02:00
parent 9344c16b7c
commit cfd1b30de4
2 changed files with 12 additions and 14 deletions

View File

@@ -168,9 +168,8 @@ def create_file(path):
return TestRun.executor.run_expect_success(cmd)
def compare(file, other_file):
output = TestRun.executor.run(
f"cmp --silent \"{file}\" \"{other_file}\"")
def compare(file, other_file, timeout: timedelta = timedelta(minutes=30)):
output = TestRun.executor.run(f"cmp --silent \"{file}\" \"{other_file}\"", timeout)
if output.exit_code == 0:
return True
elif output.exit_code > 1:
@@ -179,9 +178,8 @@ def compare(file, other_file):
return False
def diff(file, other_file):
output = TestRun.executor.run(
f"diff \"{file}\" \"{other_file}\"")
def diff(file, other_file, timeout: timedelta = timedelta(minutes=30)):
output = TestRun.executor.run(f"diff \"{file}\" \"{other_file}\"", timeout)
if output.exit_code == 0:
return None
elif output.exit_code > 1:
@@ -190,8 +188,8 @@ def diff(file, other_file):
return output.stderr
def md5sum(file, binary=True):
output = TestRun.executor.run(f"md5sum {'-b' if binary else ''} {file}")
def md5sum(file, binary=True, timeout: timedelta = timedelta(minutes=30)):
output = TestRun.executor.run(f"md5sum {'-b' if binary else ''} {file}", timeout)
if output.exit_code != 0:
raise Exception(f"Md5sum command execution failed! {output.stdout}\n{output.stderr}")
return output.stdout.split()[0]