diff options
author | Benjamin Schubert <contact@benschubert.me> | 2019-09-12 15:37:46 +0100 |
---|---|---|
committer | Benjamin Schubert <contact@benschubert.me> | 2019-10-02 13:02:18 +0100 |
commit | 2adad87fe7eed64744ef3d5e773a72a33114b3b7 (patch) | |
tree | f53489553a5ad568068e3f151668e124c17e114d /tests | |
parent | ba605659c63f69f39a206f12d7c65f92648c915a (diff) | |
download | buildstream-2adad87fe7eed64744ef3d5e773a72a33114b3b7.tar.gz |
cascache.py: Send message in case of unclean termination of buildbox-casd
This adds messages in the various mis-termination of Buildbox-casd, to
notify users that something might have gone wrong there.
It also adds a few tests to validate the various behaviors.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/internals/cascache.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/internals/cascache.py b/tests/internals/cascache.py new file mode 100644 index 000000000..8eb5cc29f --- /dev/null +++ b/tests/internals/cascache.py @@ -0,0 +1,63 @@ +import os +import time +from unittest.mock import MagicMock + +from buildstream._cas.cascache import CASCache +from buildstream._message import MessageType +from buildstream._messenger import Messenger + + +def test_report_when_cascache_dies_before_asked_to(tmp_path, monkeypatch): + dummy_buildbox_casd = tmp_path.joinpath("buildbox-casd") + dummy_buildbox_casd.write_text("#!/bin/bash\nexit 0") + dummy_buildbox_casd.chmod(0o777) + monkeypatch.setenv("PATH", str(tmp_path), prepend=os.pathsep) + + messenger = MagicMock(spec_set=Messenger) + cache = CASCache(str(tmp_path.joinpath("casd")), casd=True) + time.sleep(1) + cache.release_resources(messenger) + + assert messenger.message.call_count == 1 + + message = messenger.message.call_args[0][0] + assert message.message_type == MessageType.BUG + assert "0" in message.message + assert "died" in message.message + + +def test_report_when_cascache_exist_not_cleanly(tmp_path, monkeypatch): + dummy_buildbox_casd = tmp_path.joinpath("buildbox-casd") + dummy_buildbox_casd.write_text("#!/bin/bash\nwhile :\ndo\nsleep 60\ndone") + dummy_buildbox_casd.chmod(0o777) + monkeypatch.setenv("PATH", str(tmp_path), prepend=os.pathsep) + + messenger = MagicMock(spec_set=Messenger) + cache = CASCache(str(tmp_path.joinpath("casd")), casd=True) + time.sleep(1) + cache.release_resources(messenger) + + assert messenger.message.call_count == 1 + + message = messenger.message.call_args[0][0] + assert message.message_type == MessageType.BUG + assert "-15" in message.message + assert "cleanly" in message.message + + +def test_report_when_cascache_is_forcefully_killed(tmp_path, monkeypatch): + dummy_buildbox_casd = tmp_path.joinpath("buildbox-casd") + dummy_buildbox_casd.write_text("#!/bin/bash\ntrap 'echo hello' SIGTERM\nwhile :\ndo\nsleep 60\ndone") + dummy_buildbox_casd.chmod(0o777) + monkeypatch.setenv("PATH", str(tmp_path), prepend=os.pathsep) + + messenger = MagicMock(spec_set=Messenger) + cache = CASCache(str(tmp_path.joinpath("casd")), casd=True) + time.sleep(1) + cache.release_resources(messenger) + + assert messenger.message.call_count == 1 + + message = messenger.message.call_args[0][0] + assert message.message_type == MessageType.WARN + assert "killed" in message.message |