1
0

test_transport.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import
  4. import logging
  5. from salt.transport import MessageClientPool
  6. # Import Salt Testing libs
  7. from tests.support.unit import TestCase
  8. log = logging.getLogger(__name__)
  9. class MessageClientPoolTest(TestCase):
  10. class MockClass(object):
  11. def __init__(self, *args, **kwargs):
  12. self.args = args
  13. self.kwargs = kwargs
  14. def test_init(self):
  15. opts = {'sock_pool_size': 10}
  16. args = (0,)
  17. kwargs = {'kwarg': 1}
  18. message_client_pool = MessageClientPool(self.MockClass, opts, args=args, kwargs=kwargs)
  19. self.assertEqual(opts['sock_pool_size'], len(message_client_pool.message_clients))
  20. for message_client in message_client_pool.message_clients:
  21. self.assertEqual(message_client.args, args)
  22. self.assertEqual(message_client.kwargs, kwargs)
  23. def test_init_without_config(self):
  24. opts = {}
  25. args = (0,)
  26. kwargs = {'kwarg': 1}
  27. message_client_pool = MessageClientPool(self.MockClass, opts, args=args, kwargs=kwargs)
  28. # The size of pool is set as 1 by the MessageClientPool init method.
  29. self.assertEqual(1, len(message_client_pool.message_clients))
  30. for message_client in message_client_pool.message_clients:
  31. self.assertEqual(message_client.args, args)
  32. self.assertEqual(message_client.kwargs, kwargs)
  33. def test_init_less_than_one(self):
  34. opts = {'sock_pool_size': -1}
  35. args = (0,)
  36. kwargs = {'kwarg': 1}
  37. message_client_pool = MessageClientPool(self.MockClass, opts, args=args, kwargs=kwargs)
  38. # The size of pool is set as 1 by the MessageClientPool init method.
  39. self.assertEqual(1, len(message_client_pool.message_clients))
  40. for message_client in message_client_pool.message_clients:
  41. self.assertEqual(message_client.args, args)
  42. self.assertEqual(message_client.kwargs, kwargs)