def test_should_check(self): config = ChecksConfig(last_check=now()) assert config.should_check(-1) is False assert config.should_check(0) is True config.last_check = now() - timedelta(seconds=10000) assert config.should_check(-1) is False assert config.should_check() is True assert config.should_check(100) is True assert config.should_check(100000) is False
def test_get_interval(self): config = ChecksConfig() assert config.get_interval(1) == 1 assert config.get_interval(-1) == -1 assert config.get_interval(-2) == -2 assert config.get_interval() == ChecksConfig.INTERVAL os.environ[POLYAXON_KEYS_INTERVALS_COMPATIBILITY_CHECK] = "-1" assert config.get_interval() == -1 os.environ[POLYAXON_KEYS_INTERVALS_COMPATIBILITY_CHECK] = "-2" assert config.get_interval() == ChecksConfig.INTERVAL os.environ[POLYAXON_KEYS_INTERVALS_COMPATIBILITY_CHECK] = "1" assert config.get_interval() == ChecksConfig.INTERVAL os.environ[POLYAXON_KEYS_INTERVALS_COMPATIBILITY_CHECK] = str( ChecksConfig.INTERVAL + 1) assert config.get_interval() == ChecksConfig.INTERVAL + 1
def ping(cls): ChecksConfig.init_file(cls.HEALTH_FILE) config = cls.get_healthz_config() if config: config.last_check = now() config.write(cls.HEALTH_FILE)
def get_healthz_config(cls): try: return ChecksConfig.read(cls.HEALTH_FILE, config_type=".json") except: return
def test_get_interval(self): config = ChecksConfig() assert config.get_interval(1) == 1 assert config.get_interval() == ChecksConfig.INTERVAL