def _cmd_sleep(self, sleep_streak, quarantined): out = { 'cmd': 'sleep', 'duration': task_scheduler.exponential_backoff(sleep_streak), 'quarantined': quarantined, } self.send_response(out)
def _cmd_sleep(self, sleep_streak, quarantined): duration = task_scheduler.exponential_backoff(sleep_streak) logging.debug('Sleep: streak: %d; duration: %ds; quarantined: %s', sleep_streak, duration, quarantined) out = { 'cmd': 'sleep', 'duration': duration, 'quarantined': quarantined, } self.send_response(out)
def test_exponential_backoff(self): self.mock(task_scheduler.random, 'random', lambda: task_scheduler._PROBABILITY_OF_QUICK_COMEBACK) self.mock(utils, 'is_canary', lambda: False) data = [ (0, 2), (1, 2), (2, 3), (3, 5), (4, 8), (5, 11), (6, 17), (7, 26), (8, 38), (9, 58), (10, 60), (11, 60), ] for value, expected in data: actual = int(round(task_scheduler.exponential_backoff(value))) self.assertEqual(expected, actual, (value, expected, actual))
def test_exponential_backoff(self): self.mock( task_scheduler.random, 'random', lambda: task_scheduler._PROBABILITY_OF_QUICK_COMEBACK) self.mock(utils, 'is_canary', lambda: False) data = [ (0, 2), (1, 2), (2, 3), (3, 5), (4, 8), (5, 11), (6, 17), (7, 26), (8, 38), (9, 58), (10, 60), (11, 60), ] for value, expected in data: actual = int(round(task_scheduler.exponential_backoff(value))) self.assertEqual(expected, actual, (value, expected, actual))
def test_exponential_backoff_quick(self): self.mock( task_scheduler.random, 'random', lambda: task_scheduler._PROBABILITY_OF_QUICK_COMEBACK - 0.01) self.assertEqual(1.0, task_scheduler.exponential_backoff(235))
def _cmd_sleep(self, sleep_streak, quarantined): out = {"cmd": "sleep", "duration": task_scheduler.exponential_backoff(sleep_streak), "quarantined": quarantined} self.send_response(out)
def test_exponential_backoff_quick(self): self.mock(task_scheduler.random, 'random', lambda: task_scheduler._PROBABILITY_OF_QUICK_COMEBACK - 0.01) self.assertEqual(1.0, task_scheduler.exponential_backoff(235))