summaryrefslogtreecommitdiffstats
path: root/test/units/utils
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2022-06-07 17:31:56 +0200
committerGitHub <noreply@github.com>2022-06-07 17:31:56 +0200
commit5e369604e1930b1a2e071fecd7ec5276ebd12cb1 (patch)
tree23e177f015c738b4ea36f69552818b62ae84afc6 /test/units/utils
parentAdd macOS fork issue to FAQ (#77965) (diff)
downloadansible-5e369604e1930b1a2e071fecd7ec5276ebd12cb1.tar.xz
ansible-5e369604e1930b1a2e071fecd7ec5276ebd12cb1.zip
Forked display via queue (#77056)
* Forked Display via queue * Docs and simple code cleanup * Only proxy Display.display * Remove unused import * comment * Update deadlock comment, remove py3 check * Don't flush display, and don't lock from forks * clog frag * ci_complete ci_coverage * Add units for queue proxying * Cleanup flush * ci_complete * Only lock the write, switch to RLock * Remove unused import
Diffstat (limited to 'test/units/utils')
-rw-r--r--test/units/utils/test_display.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/units/utils/test_display.py b/test/units/utils/test_display.py
index 4883a5becc..f0a6b6eefb 100644
--- a/test/units/utils/test_display.py
+++ b/test/units/utils/test_display.py
@@ -11,6 +11,7 @@ import pytest
from ansible.module_utils.six import PY3
from ansible.utils.display import Display, get_text_width, initialize_locale
+from ansible.utils.multiprocessing import context as multiprocessing_context
def test_get_text_width():
@@ -63,3 +64,52 @@ def test_Display_banner_get_text_width_fallback(monkeypatch):
msg = args[0]
stars = u' %s' % (77 * u'*')
assert msg.endswith(stars)
+
+
+def test_Display_set_queue_parent():
+ display = Display()
+ pytest.raises(RuntimeError, display.set_queue, 'foo')
+
+
+def test_Display_set_queue_fork():
+ def test():
+ display = Display()
+ display.set_queue('foo')
+ assert display._final_q == 'foo'
+ p = multiprocessing_context.Process(target=test)
+ p.start()
+ p.join()
+ assert p.exitcode == 0
+
+
+def test_Display_display_fork():
+ def test():
+ queue = MagicMock()
+ display = Display()
+ display.set_queue(queue)
+ display.display('foo')
+ queue.send_display.assert_called_once_with(
+ 'foo', color=None, stderr=False, screen_only=False, log_only=False, newline=True
+ )
+
+ p = multiprocessing_context.Process(target=test)
+ p.start()
+ p.join()
+ assert p.exitcode == 0
+
+
+def test_Display_display_lock(monkeypatch):
+ lock = MagicMock()
+ display = Display()
+ monkeypatch.setattr(display, '_lock', lock)
+ display.display('foo')
+ lock.__enter__.assert_called_once_with()
+
+
+def test_Display_display_lock_fork(monkeypatch):
+ lock = MagicMock()
+ display = Display()
+ monkeypatch.setattr(display, '_lock', lock)
+ monkeypatch.setattr(display, '_final_q', MagicMock())
+ display.display('foo')
+ lock.__enter__.assert_not_called()