Skip to content

Instantly share code, notes, and snippets.

@adhorn
Created July 11, 2019 12:12
Show Gist options
  • Save adhorn/128cccc96f623b171c10084ffdeb6bfa to your computer and use it in GitHub Desktop.
Save adhorn/128cccc96f623b171c10084ffdeb6bfa to your computer and use it in GitHub Desktop.
@corrupt_exception decorator
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