1
0

test_queue.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. """
  3. unit tests for the cache runner
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import os
  7. import salt.runners.queue as queue_mod
  8. from tests.support.helpers import slowTest
  9. from tests.support.mixins import LoaderModuleMockMixin
  10. from tests.support.mock import MagicMock, patch
  11. from tests.support.runtests import RUNTIME_VARS
  12. from tests.support.unit import TestCase
  13. class QueueTest(TestCase, LoaderModuleMockMixin):
  14. """
  15. Validate the queue runner
  16. """
  17. def setup_loader_modules(self):
  18. return {
  19. queue_mod: {
  20. "__opts__": {
  21. "sock_dir": os.path.join(RUNTIME_VARS.TMP, "queue-runner-sock-dir"),
  22. "transport": "zeromq",
  23. }
  24. }
  25. }
  26. def test_insert_runner(self):
  27. queue_insert = MagicMock(return_value=True)
  28. with patch.object(queue_mod, "insert", queue_insert):
  29. queue_mod.insert_runner("test.stdout_print", queue="salt")
  30. expected_call = {
  31. "queue": "salt",
  32. "items": {"fun": "test.stdout_print", "args": [], "kwargs": {}},
  33. "backend": "pgjsonb",
  34. }
  35. queue_insert.assert_called_once_with(**expected_call)
  36. @slowTest
  37. def test_process_runner(self):
  38. ret = [{"fun": "test.stdout_print", "args": [], "kwargs": {}}]
  39. queue_pop = MagicMock(return_value=ret)
  40. test_stdout_print = MagicMock(return_value=True)
  41. with patch.dict(queue_mod.__salt__, {"test.stdout_print": test_stdout_print}):
  42. with patch.object(queue_mod, "pop", queue_pop):
  43. queue_mod.process_runner(queue="salt")
  44. queue_pop.assert_called_once_with(
  45. is_runner=True, queue="salt", quantity=1, backend="pgjsonb"
  46. )
  47. test_stdout_print.assert_called_once_with()
  48. queue_pop.assert_called_once_with(
  49. is_runner=True, queue="salt", quantity=1, backend="pgjsonb"
  50. )