1
0

test_transport.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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(
  19. self.MockClass, opts, args=args, kwargs=kwargs
  20. )
  21. self.assertEqual(
  22. opts["sock_pool_size"], len(message_client_pool.message_clients)
  23. )
  24. for message_client in message_client_pool.message_clients:
  25. self.assertEqual(message_client.args, args)
  26. self.assertEqual(message_client.kwargs, kwargs)
  27. def test_init_without_config(self):
  28. opts = {}
  29. args = (0,)
  30. kwargs = {"kwarg": 1}
  31. message_client_pool = MessageClientPool(
  32. self.MockClass, opts, args=args, kwargs=kwargs
  33. )
  34. # The size of pool is set as 1 by the MessageClientPool init method.
  35. self.assertEqual(1, len(message_client_pool.message_clients))
  36. for message_client in message_client_pool.message_clients:
  37. self.assertEqual(message_client.args, args)
  38. self.assertEqual(message_client.kwargs, kwargs)
  39. def test_init_less_than_one(self):
  40. opts = {"sock_pool_size": -1}
  41. args = (0,)
  42. kwargs = {"kwarg": 1}
  43. message_client_pool = MessageClientPool(
  44. self.MockClass, opts, args=args, kwargs=kwargs
  45. )
  46. # The size of pool is set as 1 by the MessageClientPool init method.
  47. self.assertEqual(1, len(message_client_pool.message_clients))
  48. for message_client in message_client_pool.message_clients:
  49. self.assertEqual(message_client.args, args)
  50. self.assertEqual(message_client.kwargs, kwargs)