Created
July 11, 2019 12:13
-
-
Save adhorn/8ac815eb546d79a0ab7717ef8278ac77 to your computer and use it in GitHub Desktop.
@corrupt_statuscode 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_statuscode(func): | |
def wrapper(*args, **kwargs): | |
result = func(*args, **kwargs) | |
error_code, rate = get_config('error_code') | |
if not error_code: | |
return result | |
print("Error from config {0} at a rate of {1}".format(error_code, rate)) | |
# add injection approx rate% of the time | |
if random.random() <= rate: | |
print("corrupting now") | |
result['statusCode'] = error_code | |
return result | |
else: | |
return result | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment