Ignore:
Timestamp:
26 Sep 2014, 11:05:08 (10 years ago)
Author:
uli
Message:

Test integer values as expensive action blockers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_utils.py

    r11819 r11821  
    1919##
    2020import psutil
     21import sys
    2122import unittest
    2223from waeup.kofa.interfaces import IKofaUtils
     
    2627
    2728class 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
    2834
    2935    def get_cleared_util(self):
     
    5662        # We can react to high swap values
    5763        utils = self.get_cleared_util()
    58         utils.SYSTEM_MAX_LOAD['swap-mem'] = 99.0    # positive number
     64        utils.SYSTEM_MAX_LOAD['swap-mem'] = 99.0           # positive float
    5965        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
    6171        assert utils.expensive_actions_allowed() == True
    6272
     
    6777        # We can react if too much swap is used
    6878        utils = self.get_cleared_util()
    69         utils.SYSTEM_MAX_LOAD['swap-mem'] = 0.0     # positive number
     79        utils.SYSTEM_MAX_LOAD['swap-mem'] = 0.0            # positive float
    7080        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
    7286        assert utils.expensive_actions_allowed() == False
    7387
     
    87101        # We can react to high virtmem values
    88102        utils = self.get_cleared_util()
    89         utils.SYSTEM_MAX_LOAD['virt-mem'] = 99.0    # positive number
     103        utils.SYSTEM_MAX_LOAD['virt-mem'] = 99.0           # positive float
    90104        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
    92110        assert utils.expensive_actions_allowed() == True
    93111
     
    98116        # We can react if too much virtmem is used
    99117        utils = self.get_cleared_util()
    100         utils.SYSTEM_MAX_LOAD['virt-mem'] = 0.0     # positive number
     118        utils.SYSTEM_MAX_LOAD['virt-mem'] = 0.0            # positive float
    101119        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
    103125        assert utils.expensive_actions_allowed() == False
    104126
     
    113135
    114136    @unittest.skipIf(
    115         psutil.phymem_usage().percent >= 99.0,
     137        psutil.phymem_usage().percent >= 99.99,
    116138        reason="System physmem use over 99%. Cannot set higher allowed value.")
    117139    def test_expensive_actions_allowed_physmem_ok(self):
    118140        # We can react to high physmem values
     141        max_mem = psutil.phymem_usage().total
    119142        utils = self.get_cleared_util()
    120         utils.SYSTEM_MAX_LOAD['phys-mem'] = 99.0    # positive number
     143        utils.SYSTEM_MAX_LOAD['phys-mem'] = 99.99          # positive float
    121144        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
    123150        assert utils.expensive_actions_allowed() == True
    124151
     
    128155    def test_expensive_actions_allowed_physmem_too_much(self):
    129156        # We can react if too much physmem is used
     157        max_mem = psutil.phymem_usage().total
    130158        utils = self.get_cleared_util()
    131         utils.SYSTEM_MAX_LOAD['phys-mem'] = 0.0     # positive number
     159        utils.SYSTEM_MAX_LOAD['phys-mem'] = 0.0            # positive float
    132160        assert utils.expensive_actions_allowed() == False
    133         utils.SYSTEM_MAX_LOAD['phys-mem'] = -100.0  # negative number
     161        utils.SYSTEM_MAX_LOAD['phys-mem'] = -100.0         # negative float
    134162        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.