From cfd1b30de440eddc52d2d3b44e578acc15dcbd04 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Wed, 2 Oct 2024 21:52:08 +0200 Subject: [PATCH] Introduce option to define timeout for time-consuming file operations Signed-off-by: Robert Baldyga --- test_tools/fs_utils.py | 14 ++++++-------- test_utils/filesystem/file.py | 12 ++++++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/test_tools/fs_utils.py b/test_tools/fs_utils.py index cd5daa1..464254f 100644 --- a/test_tools/fs_utils.py +++ b/test_tools/fs_utils.py @@ -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] diff --git a/test_utils/filesystem/file.py b/test_utils/filesystem/file.py index 7edaa42..9554222 100644 --- a/test_utils/filesystem/file.py +++ b/test_utils/filesystem/file.py @@ -14,14 +14,14 @@ class File(FsItem): def __init__(self, full_path): FsItem.__init__(self, full_path) - def compare(self, other_file): - return fs_utils.compare(str(self), str(other_file)) + def compare(self, other_file, timeout: timedelta = timedelta(minutes=30)): + return fs_utils.compare(str(self), str(other_file), timeout) - def diff(self, other_file): - return fs_utils.diff(str(self), str(other_file)) + def diff(self, other_file, timeout: timedelta = timedelta(minutes=30)): + return fs_utils.diff(str(self), str(other_file), timeout) - def md5sum(self, binary=True): - return fs_utils.md5sum(str(self), binary) + def md5sum(self, binary=True, timeout: timedelta = timedelta(minutes=30)): + return fs_utils.md5sum(str(self), binary, timeout) def read(self): return fs_utils.read_file(str(self))