def test_exception(self): """Test raising exception.""" task = mock.Mock() task.command = 'task' task.job = 'job' with self.assertRaises(Exception): with run_bot._Monitor(task, time_module=self.time): self.time.advance(5) raise Exception('test') self.assertEqual( 1, monitoring_metrics.TASK_COUNT.get({ 'task': 'task', 'job': 'job' })) task_time = monitoring_metrics.TASK_TIME.get({ 'task': 'task', 'job': 'job', 'error': True }) self.assertEqual(5, task_time.sum) self.assertEqual(1, task_time.count) expected_buckets = [0 for _ in xrange(102)] expected_buckets[14] = 1 self.assertListEqual(expected_buckets, task_time.buckets)
def test_empty(self): """Test empty.""" task = mock.Mock() task.command = None task.job = None with run_bot._Monitor(task, time_module=self.time): self.time.advance(5) self.assertEqual(1, monitoring_metrics.TASK_COUNT.get({ 'task': '', 'job': '' })) task_time = monitoring_metrics.TASK_TIME.get({ 'task': '', 'job': '', 'error': False }) self.assertEqual(5, task_time.sum) self.assertEqual(1, task_time.count) expected_buckets = [0 for _ in xrange(102)] expected_buckets[14] = 1 self.assertListEqual(expected_buckets, task_time.buckets)
def test_empty(self): """Test empty.""" task = mock.Mock() task.command = None task.job = None with run_bot._Monitor(task, time_module=self.time): self.time.advance(5) self.assertEqual( 1, monitoring_metrics.TASK_COUNT.get({ 'task': '', 'job': '' }))
def test_succeed(self): """Test succeed.""" task = mock.Mock() task.command = 'task' task.job = 'job' with run_bot._Monitor(task, time_module=self.time): self.time.advance(5) self.assertEqual( 1, monitoring_metrics.TASK_COUNT.get({ 'task': 'task', 'job': 'job' }))
def test_exception(self): """Test raising exception.""" task = mock.Mock() task.command = 'task' task.job = 'job' with self.assertRaises(Exception): with run_bot._Monitor(task, time_module=self.time): self.time.advance(5) raise Exception('test') self.assertEqual( 1, monitoring_metrics.TASK_COUNT.get({ 'task': 'task', 'job': 'job' }))