Ignore:
Timestamp:
24 Sep 2014, 15:25:32 (10 years ago)
Author:
uli
Message:

Test virtual memory checker.

File:
1 edited

Legend:

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

    r11816 r11817  
    7171        utils.SYSTEM_MAX_LOAD['swap-mem'] = -100.0  # negative number
    7272        assert utils.expensive_actions_allowed() == False
     73
     74    def test_expensive_actions_allowed_virtmem_none(self):
     75        # unset virtmem maximum values make KofUtils ignore virtmem values
     76        utils = self.get_cleared_util()
     77        utils.SYSTEM_MAX_LOAD['virt-mem'] = None
     78        assert utils.expensive_actions_allowed() == True
     79        # even not-set values won't block us
     80        del utils.SYSTEM_MAX_LOAD['virt-mem']
     81        assert utils.expensive_actions_allowed() == True
     82
     83    @unittest.skipIf(
     84        psutil.virtual_memory().percent >= 99.0,
     85        reason="System virtmem use over 99%. Cannot set higher allowed value.")
     86    def test_expensive_actions_allowed_virtmem_ok(self):
     87        # We can react to high virtmem values
     88        utils = self.get_cleared_util()
     89        utils.SYSTEM_MAX_LOAD['virt-mem'] = 99.0    # positive number
     90        assert utils.expensive_actions_allowed() == True
     91        utils.SYSTEM_MAX_LOAD['virt-mem'] = -1.0    # negative number
     92        assert utils.expensive_actions_allowed() == True
     93
     94    @unittest.skipIf(
     95        not psutil.virtual_memory().percent,
     96        reason="Can test virtmem behavior only if actually using some")
     97    def test_expensive_actions_allowed_virtmem_too_much(self):
     98        # We can react if too much virtmem is used
     99        utils = self.get_cleared_util()
     100        utils.SYSTEM_MAX_LOAD['virt-mem'] = 0.0     # positive number
     101        assert utils.expensive_actions_allowed() == False
     102        utils.SYSTEM_MAX_LOAD['virt-mem'] = -100.0  # negative number
     103        assert utils.expensive_actions_allowed() == False
Note: See TracChangeset for help on using the changeset viewer.