本文整理匯總了Python中otter.tap.api.HealthChecker類的典型用法代碼示例。如果您正苦於以下問題:Python HealthChecker類的具體用法?Python HealthChecker怎麽用?Python HealthChecker使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了HealthChecker類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_no_checks
def test_no_checks(self):
"""
If there are no checks, HealthChecker returns healthy
"""
checker = HealthChecker(self.clock)
d = checker.health_check()
self.assertEqual(self.successResultOf(d), {'healthy': True})
示例2: test_invalid_check
def test_invalid_check(self):
"""
If an invalid check is added, its health is unhealthy
"""
checker = HealthChecker(self.clock, {'invalid': None})
d = checker.health_check()
self.assertEqual(self.successResultOf(d), {
'healthy': False,
'invalid': {
'healthy': False,
'details': {'reason': mock.ANY}
}
})
示例3: test_synchronous_health_check
def test_synchronous_health_check(self):
"""
Synchronous health checks are supported
"""
checker = HealthChecker(self.clock, {'sync': mock.Mock(return_value=(True, {}))})
d = checker.health_check()
self.assertEqual(self.successResultOf(d), {
'healthy': True,
'sync': {
'healthy': True,
'details': {}
}
})
示例4: test_check_failure
def test_check_failure(self):
"""
If a check raises an exception, its health is unhealthy
"""
checker = HealthChecker(self.clock, {'fail': mock.Mock(side_effect=Exception)})
d = checker.health_check()
self.assertEqual(self.successResultOf(d), {
'healthy': False,
'fail': {
'healthy': False,
'details': {'reason': matches(Contains('Exception'))}
}
})
示例5: test_check_is_timed_out
def test_check_is_timed_out(self):
"""
Each health check is timed out after 15 seconds
"""
checker = HealthChecker(
self.clock, {'a': mock.Mock(return_value=defer.Deferred()),
'b': mock.Mock(return_value=defer.succeed((True, {})))})
d = checker.health_check()
self.assertNoResult(d)
self.clock.advance(16)
r = self.successResultOf(d)
self.assertEqual(r, {
'healthy': False,
'a': {'healthy': False, 'details': {'reason': mock.ANY}},
'b': {'healthy': True, 'details': {}}
})
self.assertIn('a health check timed out', r['a']['details']['reason'])
示例6: test_one_failed_health_fails_overall_health
def test_one_failed_health_fails_overall_health(self):
"""
All health checks must pass in order for the main check to be healthy
"""
checker = HealthChecker(self.clock, {
'healthy_thing': mock.Mock(return_value=(True, {})),
'unhealthy_thing': mock.Mock(return_value=(False, {}))
})
d = checker.health_check()
self.assertEqual(self.successResultOf(d), {
'healthy': False,
'healthy_thing': {
'healthy': True,
'details': {}
},
'unhealthy_thing': {
'healthy': False,
'details': {}
}
})
示例7: test_all_health_passes_means_overall_health_passes
def test_all_health_passes_means_overall_health_passes(self):
"""
When all health checks pass the overall check is healthy
"""
checker = HealthChecker(self.clock, dict([
("check{0}".format(i), mock.Mock(return_value=(True, {})))
for i in range(3)
]))
d = checker.health_check()
self.assertEqual(self.successResultOf(d), {
'healthy': True,
'check0': {
'healthy': True,
'details': {}
},
'check1': {
'healthy': True,
'details': {}
},
'check2': {
'healthy': True,
'details': {}
}
})