-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Healthcheck scenarios for diagnosis (proof of concept) #23
Comments
Not sure nose's test generators do the trick... @hospital.healthcheck
def test_example_com():
yield check_http_200
yield check_ping
def check_http_200():
hospital.assert_http_response('http://example.com', status_code=200, timeout=1)
def check_ping():
hospital.assert_ping('example.com') In the healthcheck (test_example_com) function, I do not know how to do the switch: I would like to switch on the test result, not on the callable. Whatever the result of |
Perhaps using a TestSuite with implementation of either |
Note: the following is not what we need: def test_something():
hospital.assert_http_response('http://example.com')
hospital.assert_ping('example.com') If the first assertion succeeds, the second one is also triggered. => I want the second assertion to be triggered only if the first one failed. |
A naive implementation could be: logger = logging.getLogger('healthchecks')
@hospital.healthcheck
def test_example_com():
try:
hospital.assert_http_response('http://example.com')
except AssertionError as e:
logger.error(e) # Report error! But do not stop execution.
hospital.assert_ping('example.com') The implementation above implements a scenario, but there are some drawbacks:
|
Quickly tried to declare a subclass of I.e. something like this does not trigger the class PredictableTestSuite(unittest.TestSuite):
def run(self, result):
assert False |
Another idea about making scenarios is to use test attributes: have a set of healtchecks with additional "is_smoketest" attribute. In order to get the service status, I run only smoketests => if everything passed, then there is no need to run more checks. import hospital
@hospital.smoketest
def test_http_200():
hospital.assert_http_response('http://example.com', status_code=200, timeout=1)
@hospital.healthcheck
def check_ping():
hospital.assert_ping('example.com') |
Let's implement #35 for version 0.4 and delay this one. |
Scenarios make it possible to run further checks in case of a failure.
As an example, if http://example.com does not return HTTP 200 within 1 second, run additional checks to diagnose the issue, such as does example.com responds to ping?
The text was updated successfully, but these errors were encountered: