Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
webbnh committed Jul 31, 2023
1 parent b22cee5 commit 6507be1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
4 changes: 4 additions & 0 deletions lib/pbench/server/cache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,10 @@ def extract(tarball_path: Path, path: str) -> Inventory:

elapsed = time.time() - start
if elapsed > Tarball.TAR_EXEC_TIMEOUT:
# No signs of life from the subprocess. Kill it to ensure that
# the Python runtime can clean it up after we leave, and report
# the failure.
tarproc.kill()
raise subprocess.TimeoutExpired(
cmd=tar_command,
timeout=elapsed,
Expand Down
28 changes: 10 additions & 18 deletions lib/pbench/test/unit/server/test_cache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def fake_get_metadata(_tb_path):
return {"pbench": {"date": "2002-05-16T00:00:00"}, "run": {"controller": "ABC"}}


MEMBER_NOT_FOUND_MSG = b"mock-tar: metadata.log: Not found in mock-archive"
CANNOT_OPEN_MSG = (
b"mock-tar: /mock/result.tar.xz: Cannot open: No such mock-file or mock-directory"
)


class TestCacheManager:
def test_create(self, server_config, make_logger):
"""
Expand Down Expand Up @@ -955,25 +961,9 @@ def mock_find_dataset(_self, dataset: str) -> MockTarball:
# Loop/sleep twice, then success
("/usr/bin/tar", False, 2, b"[test]", None, 0, b""),
# Member path failure
(
"/usr/bin/tar",
False,
0,
b"",
1,
1,
b"mock-tar: metadata.log: Not found in mock-archive",
),
("/usr/bin/tar", False, 0, b"", 1, 1, MEMBER_NOT_FOUND_MSG),
# Archive access failure
(
"/usr/bin/tar",
False,
0,
b"",
1,
1,
b"mock-tar: /mock/result.tar.xz: Cannot open: No such mock-file or mock-directory",
),
("/usr/bin/tar", False, 0, b"", 1, 1, CANNOT_OPEN_MSG),
# Unexpected failure
("/usr/bin/tar", False, 0, b"", 1, 1, b"mock-tar: bolt out of the blue!"),
# Hang, never returning output nor an exit code
Expand Down Expand Up @@ -1058,6 +1048,7 @@ def mock_shutil_which(
except CacheExtractBadPath as exc:
assert tar_path
assert not popen_fail
assert stderr_contents == MEMBER_NOT_FOUND_MSG
assert str(exc) == f"Unable to extract {path} from {tar.name}"
except subprocess.TimeoutExpired as exc:
assert tar_path
Expand All @@ -1071,6 +1062,7 @@ def mock_shutil_which(
else:
assert not popen_fail
msg = f"Unexpected error from {tar_path}: {stderr_contents.decode()!r}"
assert stderr_contents != MEMBER_NOT_FOUND_MSG
assert str(exc) == f"An error occurred while unpacking {tar}: {msg}"
except ValueError:
assert tar_path
Expand Down

0 comments on commit 6507be1

Please sign in to comment.