test_sysbench.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Jayesh Kariya <jayeshk@saltstack.com>
  4. """
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Libs
  8. import salt.modules.sysbench as sysbench
  9. # Import Salt Testing Libs
  10. from tests.support.mixins import LoaderModuleMockMixin
  11. from tests.support.mock import MagicMock, patch
  12. from tests.support.unit import TestCase
  13. class SysbenchTestCase(TestCase, LoaderModuleMockMixin):
  14. """
  15. Test cases to salt.modules.sysbench
  16. """
  17. def setup_loader_modules(self):
  18. return {sysbench: {}}
  19. def test_cpu(self):
  20. """
  21. Test to tests to the CPU performance of minions.
  22. """
  23. with patch.dict(
  24. sysbench.__salt__, {"cmd.run": MagicMock(return_value={"A": "a"})}
  25. ):
  26. with patch.object(sysbench, "_parser", return_value={"A": "a"}):
  27. self.assertEqual(
  28. sysbench.cpu(),
  29. {
  30. "Prime numbers limit: 500": {"A": "a"},
  31. "Prime numbers limit: 5000": {"A": "a"},
  32. "Prime numbers limit: 2500": {"A": "a"},
  33. "Prime numbers limit: 1000": {"A": "a"},
  34. },
  35. )
  36. def test_threads(self):
  37. """
  38. Test to this tests the performance of the processor's scheduler
  39. """
  40. with patch.dict(
  41. sysbench.__salt__, {"cmd.run": MagicMock(return_value={"A": "a"})}
  42. ):
  43. with patch.object(sysbench, "_parser", return_value={"A": "a"}):
  44. self.assertEqual(
  45. sysbench.threads(),
  46. {
  47. "Yields: 500 Locks: 8": {"A": "a"},
  48. "Yields: 200 Locks: 4": {"A": "a"},
  49. "Yields: 1000 Locks: 16": {"A": "a"},
  50. "Yields: 100 Locks: 2": {"A": "a"},
  51. },
  52. )
  53. def test_mutex(self):
  54. """
  55. Test to tests the implementation of mutex
  56. """
  57. with patch.dict(
  58. sysbench.__salt__, {"cmd.run": MagicMock(return_value={"A": "a"})}
  59. ):
  60. with patch.object(sysbench, "_parser", return_value={"A": "a"}):
  61. self.assertEqual(
  62. sysbench.mutex(),
  63. {
  64. "Mutex: 1000 Locks: 25000 Loops: 10000": {"A": "a"},
  65. "Mutex: 50 Locks: 10000 Loops: 2500": {"A": "a"},
  66. "Mutex: 1000 Locks: 10000 Loops: 5000": {"A": "a"},
  67. "Mutex: 500 Locks: 50000 Loops: 5000": {"A": "a"},
  68. "Mutex: 500 Locks: 25000 Loops: 2500": {"A": "a"},
  69. "Mutex: 500 Locks: 10000 Loops: 10000": {"A": "a"},
  70. "Mutex: 50 Locks: 50000 Loops: 10000": {"A": "a"},
  71. "Mutex: 1000 Locks: 50000 Loops: 2500": {"A": "a"},
  72. "Mutex: 50 Locks: 25000 Loops: 5000": {"A": "a"},
  73. },
  74. )
  75. def test_memory(self):
  76. """
  77. Test to this tests the memory for read and write operations.
  78. """
  79. with patch.dict(
  80. sysbench.__salt__, {"cmd.run": MagicMock(return_value={"A": "a"})}
  81. ):
  82. with patch.object(sysbench, "_parser", return_value={"A": "a"}):
  83. self.assertEqual(
  84. sysbench.memory(),
  85. {
  86. "Operation: read Scope: local": {"A": "a"},
  87. "Operation: write Scope: local": {"A": "a"},
  88. "Operation: read Scope: global": {"A": "a"},
  89. "Operation: write Scope: global": {"A": "a"},
  90. },
  91. )
  92. def test_fileio(self):
  93. """
  94. Test to this tests for the file read and write operations
  95. """
  96. with patch.dict(
  97. sysbench.__salt__, {"cmd.run": MagicMock(return_value={"A": "a"})}
  98. ):
  99. with patch.object(sysbench, "_parser", return_value={"A": "a"}):
  100. self.assertEqual(
  101. sysbench.fileio(),
  102. {
  103. "Mode: seqrd": {"A": "a"},
  104. "Mode: seqwr": {"A": "a"},
  105. "Mode: rndrd": {"A": "a"},
  106. "Mode: rndwr": {"A": "a"},
  107. "Mode: seqrewr": {"A": "a"},
  108. "Mode: rndrw": {"A": "a"},
  109. },
  110. )
  111. def test_ping(self):
  112. """
  113. Test to ping
  114. """
  115. self.assertTrue(sysbench.ping())