Last active
February 25, 2019 13:14
-
-
Save gunesmes/c888d89f55d13928d434 to your computer and use it in GitHub Desktop.
Integration of Locust and Jenkins.
This file contains hidden or 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
| import re, sys | |
| import os | |
| MIN_RESPONSE_TIME = int(os.environ['min_response_time']) | |
| MAX_RESPONSE_TIME = int(os.environ['max_response_time']) | |
| AVG_RESPONSE_TIME = int(os.environ['avg_response_time']) | |
| print("\n---- Test Parameters -----\n") | |
| print("MIN_RESPONSE_TIME: %d" % MIN_RESPONSE_TIME) | |
| print("MAX_RESPONSE_TIME: %d" % MAX_RESPONSE_TIME) | |
| print("AVG_RESPONSE_TIME: %d" % AVG_RESPONSE_TIME) | |
| print("\n\n---- Test Result ----\n") | |
| f = open("load_test_result_requests.csv", "r") | |
| lines = f.readlines() | |
| stats = [] | |
| for l in lines: | |
| match = re.search('\"(GET|POST)\",\"\/.*\"((,\d*){6})', l) | |
| try: | |
| stats.append(match.group(2)[1:].split(",")) | |
| except: | |
| pass | |
| (num_requests, num_failures, med_response_time, avg_response_time, min_response_time, max_response_time) = (list(x) for x in zip(*stats)) | |
| total_num_requests = sum(map(int, num_requests)) | |
| if total_num_requests == 0: | |
| sys.exit("There is no reqest, something goes wrong!") | |
| else: | |
| print("num_requests: PASSED") | |
| if not all(int(i) == 0 for i in num_failures): | |
| sys.exit("There are some requests failed") | |
| else: | |
| print("num_failures: PASSED") | |
| if not all(int(i) <= MIN_RESPONSE_TIME for i in min_response_time): | |
| sys.exit("There are some min_response_time bigger than %d ms\n MIN_RESPONSE_TIME: %s" % (MIN_RESPONSE_TIME, min_response_time)) | |
| else: | |
| print("min_response_time: PASSED") | |
| if not all(int(i) <= MAX_RESPONSE_TIME for i in max_response_time): | |
| sys.exit("There are some max_response_time bigger than %d ms\n MAX_RESPONSE_TIME: %s" % (MAX_RESPONSE_TIME, max_response_time)) | |
| else: | |
| print("max_response_time: PASSED") | |
| if not all(int(i) <= AVG_RESPONSE_TIME for i in avg_response_time): | |
| sys.exit("There are some avg_response_time bigger than %d ms\n AVG_RESPONSE_TIME: %s" % (AVG_RESPONSE_TIME, avg_response_time)) | |
| else: | |
| print("avg_response_time: PASSED") |
This file contains hidden or 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 store_stats(filename, stats): | |
| with open(filename, "w") as f: | |
| f.write("path,method,num_requests,num_failures,min_response_time,max_response_time,avg_response_time\n") | |
| for k in stats: | |
| r = stats[k] | |
| try: | |
| f.write("%s,%s,%d,%d,%d,%d,%d\n" % (r.name,r.method,r.num_requests,r.num_failures,r.min_response_time,r.max_response_time,r.avg_response_time)); | |
| except: | |
| pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't you cast
os.environ['min_response_time']to anint()?Otherwise, you're comparing int(i) with a string later, which will produce wrong results.
Also, the
%operator should be inside the argument list forsys.exit, not after it.