Changeset 11821 for main/waeup.kofa/trunk/src/waeup/kofa/utils/tests
- Timestamp:
- 26 Sep 2014, 11:05:08 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_utils.py
r11819 r11821 19 19 ## 20 20 import psutil 21 import sys 21 22 import unittest 22 23 from waeup.kofa.interfaces import IKofaUtils … … 26 27 27 28 class KofaUtilsTestCase(unittest.TestCase): 29 30 def setUp(self): 31 self.max_pmem = psutil.phymem_usage().total 32 self.max_vmem = psutil.virtual_memory().total 33 self.max_smem = psutil.swap_memory().total 28 34 29 35 def get_cleared_util(self): … … 56 62 # We can react to high swap values 57 63 utils = self.get_cleared_util() 58 utils.SYSTEM_MAX_LOAD['swap-mem'] = 99.0 # positive number64 utils.SYSTEM_MAX_LOAD['swap-mem'] = 99.0 # positive float 59 65 assert utils.expensive_actions_allowed() == True 60 utils.SYSTEM_MAX_LOAD['swap-mem'] = -1.0 # negative number 66 utils.SYSTEM_MAX_LOAD['swap-mem'] = -1.0 # negative float 67 assert utils.expensive_actions_allowed() == True 68 utils.SYSTEM_MAX_LOAD['swap-mem'] = sys.maxint # positive int 69 assert utils.expensive_actions_allowed() == True 70 utils.SYSTEM_MAX_LOAD['swap-mem'] = -1 # negative int 61 71 assert utils.expensive_actions_allowed() == True 62 72 … … 67 77 # We can react if too much swap is used 68 78 utils = self.get_cleared_util() 69 utils.SYSTEM_MAX_LOAD['swap-mem'] = 0.0 # positive number79 utils.SYSTEM_MAX_LOAD['swap-mem'] = 0.0 # positive float 70 80 assert utils.expensive_actions_allowed() == False 71 utils.SYSTEM_MAX_LOAD['swap-mem'] = -100.0 # negative number 81 utils.SYSTEM_MAX_LOAD['swap-mem'] = -100.0 # negative float 82 assert utils.expensive_actions_allowed() == False 83 utils.SYSTEM_MAX_LOAD['swap-mem'] = 0 # positive int 84 assert utils.expensive_actions_allowed() == False 85 utils.SYSTEM_MAX_LOAD['swap-mem'] = -(sys.maxint) # negative int 72 86 assert utils.expensive_actions_allowed() == False 73 87 … … 87 101 # We can react to high virtmem values 88 102 utils = self.get_cleared_util() 89 utils.SYSTEM_MAX_LOAD['virt-mem'] = 99.0 # positive number103 utils.SYSTEM_MAX_LOAD['virt-mem'] = 99.0 # positive float 90 104 assert utils.expensive_actions_allowed() == True 91 utils.SYSTEM_MAX_LOAD['virt-mem'] = -1.0 # negative number 105 utils.SYSTEM_MAX_LOAD['virt-mem'] = -1.0 # negative float 106 assert utils.expensive_actions_allowed() == True 107 utils.SYSTEM_MAX_LOAD['virt-mem'] = sys.maxint # positive int 108 assert utils.expensive_actions_allowed() == True 109 utils.SYSTEM_MAX_LOAD['virt-mem'] = -1 # negative int 92 110 assert utils.expensive_actions_allowed() == True 93 111 … … 98 116 # We can react if too much virtmem is used 99 117 utils = self.get_cleared_util() 100 utils.SYSTEM_MAX_LOAD['virt-mem'] = 0.0 # positive number118 utils.SYSTEM_MAX_LOAD['virt-mem'] = 0.0 # positive float 101 119 assert utils.expensive_actions_allowed() == False 102 utils.SYSTEM_MAX_LOAD['virt-mem'] = -100.0 # negative number 120 utils.SYSTEM_MAX_LOAD['virt-mem'] = -100.0 # negative float 121 assert utils.expensive_actions_allowed() == False 122 utils.SYSTEM_MAX_LOAD['virt-mem'] = 0 # positive int 123 assert utils.expensive_actions_allowed() == False 124 utils.SYSTEM_MAX_LOAD['virt-mem'] = -(sys.maxint) # negative int 103 125 assert utils.expensive_actions_allowed() == False 104 126 … … 113 135 114 136 @unittest.skipIf( 115 psutil.phymem_usage().percent >= 99. 0,137 psutil.phymem_usage().percent >= 99.99, 116 138 reason="System physmem use over 99%. Cannot set higher allowed value.") 117 139 def test_expensive_actions_allowed_physmem_ok(self): 118 140 # We can react to high physmem values 141 max_mem = psutil.phymem_usage().total 119 142 utils = self.get_cleared_util() 120 utils.SYSTEM_MAX_LOAD['phys-mem'] = 99. 0 # positive number143 utils.SYSTEM_MAX_LOAD['phys-mem'] = 99.99 # positive float 121 144 assert utils.expensive_actions_allowed() == True 122 utils.SYSTEM_MAX_LOAD['phys-mem'] = -1.0 # negative number 145 utils.SYSTEM_MAX_LOAD['phys-mem'] = -0.01 # negative float 146 assert utils.expensive_actions_allowed() == True 147 utils.SYSTEM_MAX_LOAD['phys-mem'] = max_mem # positive int 148 assert utils.expensive_actions_allowed() == True 149 utils.SYSTEM_MAX_LOAD['phys-mem'] = -1 # negative int 123 150 assert utils.expensive_actions_allowed() == True 124 151 … … 128 155 def test_expensive_actions_allowed_physmem_too_much(self): 129 156 # We can react if too much physmem is used 157 max_mem = psutil.phymem_usage().total 130 158 utils = self.get_cleared_util() 131 utils.SYSTEM_MAX_LOAD['phys-mem'] = 0.0 # positive number159 utils.SYSTEM_MAX_LOAD['phys-mem'] = 0.0 # positive float 132 160 assert utils.expensive_actions_allowed() == False 133 utils.SYSTEM_MAX_LOAD['phys-mem'] = -100.0 # negative number161 utils.SYSTEM_MAX_LOAD['phys-mem'] = -100.0 # negative float 134 162 assert utils.expensive_actions_allowed() == False 163 utils.SYSTEM_MAX_LOAD['phys-mem'] = 0 # positive int 164 assert utils.expensive_actions_allowed() == False 165 utils.SYSTEM_MAX_LOAD['phys-mem'] = -(max_mem) # negative int 166 assert utils.expensive_actions_allowed() == False
Note: See TracChangeset for help on using the changeset viewer.