summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-10-03 16:13:10 +0100
committerBenjamin Schubert <contact@benschubert.me>2019-10-04 16:15:23 +0100
commit0c8861edacfb90ed0f2b101fcb08a81b980dae9b (patch)
tree2401c34cab5db6ad7d9554965b8ab5207ca3d469 /tests
parent764a7cf075f0bbd6c31a312b27532749f2d7136a (diff)
downloadbuildstream-0c8861edacfb90ed0f2b101fcb08a81b980dae9b.tar.gz
cascache.py: Save casd logs in a file for retrieval
Save all casd logs in a log file under its cas/ directory, and keep only the last 10 of them.
Diffstat (limited to 'tests')
-rw-r--r--tests/internals/cascache.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/internals/cascache.py b/tests/internals/cascache.py
index 8eb5cc29f..81273aeaf 100644
--- a/tests/internals/cascache.py
+++ b/tests/internals/cascache.py
@@ -61,3 +61,42 @@ def test_report_when_cascache_is_forcefully_killed(tmp_path, monkeypatch):
message = messenger.message.call_args[0][0]
assert message.message_type == MessageType.WARN
assert "killed" in message.message
+
+
+def test_casd_redirects_stderr_to_file_and_rotate(tmp_path, monkeypatch):
+ n_max_log_files = 10
+
+ dummy_buildbox_casd = tmp_path.joinpath("buildbox-casd")
+ dummy_buildbox_casd.write_text("#!/bin/bash\necho -e hello")
+ dummy_buildbox_casd.chmod(0o777)
+ monkeypatch.setenv("PATH", str(tmp_path), prepend=os.pathsep)
+
+ casd_files_path = tmp_path.joinpath("casd")
+ casd_logs_path = casd_files_path.joinpath("cas", "logs")
+
+ # Ensure we don't have any files in the log directory
+ assert not casd_logs_path.exists()
+ existing_log_files = []
+
+ # Let's create the first `n_max_log_files` log files
+ for i in range(1, n_max_log_files + 1):
+ cache = CASCache(str(casd_files_path), casd=True)
+ time.sleep(0.05)
+ cache.release_resources()
+
+ existing_log_files = sorted(casd_logs_path.iterdir())
+ assert len(existing_log_files) == i
+ assert existing_log_files[-1].read_text() == "hello\n"
+
+ # Ensure the oldest log files get removed first
+ for _ in range(3):
+ evicted_file = existing_log_files.pop(0)
+
+ cache = CASCache(str(casd_files_path), casd=True)
+ time.sleep(0.05)
+ cache.release_resources()
+
+ existing_log_files = sorted(casd_logs_path.iterdir())
+ assert len(existing_log_files) == n_max_log_files
+ assert evicted_file not in existing_log_files
+ assert existing_log_files[-1].read_text() == "hello\n"