Created
July 11, 2019 12:12
-
-
Save adhorn/128cccc96f623b171c10084ffdeb6bfa to your computer and use it in GitHub Desktop.
@corrupt_exception decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def corrupt_exception(func): | |
def wrapper(*args, **kwargs): | |
result = func(*args, **kwargs) | |
exception_msg, rate = get_config('exception_msg') | |
if not exception_msg: | |
return result | |
print("exception_msg from config {0} with a rate of {1}".format(exception_msg, rate)) | |
# add injection approx rate% of the time | |
if random.random() <= rate: | |
print("corrupting now") | |
raise Exception(exception_msg) | |
else: | |
return result | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment