def test_config_get_new_datetime_for_delay_incremental(self): config = ErrorsHandleConfig( **{ **self.normal_config, 'retry_pause_strategy': const.DELAY_STRATEGY_INCREMENTAL, } ) now = timezone.now().timestamp() new_date = config.get_new_datetime_for_retry(2) self.assertEqual(round(new_date.timestamp() - now), 10)
def test_config_get_new_datetime_for_delay_error(self): config = ErrorsHandleConfig( **{ **self.normal_config, 'retry_pause_strategy': const.DELAY_STRATEGY_INCREMENTAL, } ) now = timezone.now().timestamp() with self.assertRaises(RuntimeError): new_date = config.get_new_datetime_for_retry(5)
class ConfiguredFailingTestTaskProcessor(BaseTaskProcessor): RETRY_ON_ERROR_CONFIG = ErrorsHandleConfig( retry_on_errors=[ ValueError, ], retries_count=5, retry_pause=0, ) def run(self): raise ValueError()
def test_config_get_new_datetime_for_delay_constant(self): config = ErrorsHandleConfig(**self.normal_config) now = timezone.now().timestamp() new_date = config.get_new_datetime_for_retry(2) self.assertEqual(round(new_date.timestamp() - now), 5)
def test_config_should_be_retried(self): config = ErrorsHandleConfig(**self.normal_config) self.assertTrue(config.shoud_be_retried(1)) self.assertFalse(config.shoud_be_retried(3))
def test_validation_bad_strategy(self): with self.assertRaises(ValueError): ErrorsHandleConfig( **{**self.normal_config, 'retry_pause_strategy': 'not strategy id'} )
def test_validation_negative_pause(self): with self.assertRaises(ValueError): ErrorsHandleConfig(**{**self.normal_config, 'retry_pause': -1})
def test_validation_zero_retries(self): with self.assertRaises(ValueError): ErrorsHandleConfig(**{**self.normal_config, 'retries_count': 0})
def test_validation_not_errors(self): with self.assertRaises(ValueError): ErrorsHandleConfig( **{**self.normal_config, 'retry_on_errors': ['not exception']} )