2020-09-23 13:28:42 -04:00
|
|
|
from locust import task, between, SequentialTaskSet
|
|
|
|
from locust.contrib.fasthttp import FastHttpUser
|
2021-04-02 06:47:07 -04:00
|
|
|
from locust import events
|
2020-09-23 13:28:42 -04:00
|
|
|
import json
|
2021-04-02 06:47:07 -04:00
|
|
|
import logging
|
|
|
|
|
|
|
|
@events.quitting.add_listener
|
|
|
|
def _(environment, **kw):
|
|
|
|
if environment.stats.total.fail_ratio > 0.02:
|
|
|
|
logging.error("Test failed due to failure ratio > 2%")
|
|
|
|
environment.process_exit_code = 1
|
|
|
|
elif environment.stats.total.avg_response_time > 300:
|
|
|
|
logging.error("Test failed due to average response time ratio > 300 ms")
|
|
|
|
environment.process_exit_code = 1
|
|
|
|
elif environment.stats.total.get_response_time_percentile(0.95) > 800:
|
|
|
|
logging.error("Test failed due to 95th percentile response time > 800 ms")
|
|
|
|
environment.process_exit_code = 1
|
|
|
|
else:
|
|
|
|
environment.process_exit_code = 0
|
2020-09-23 13:28:42 -04:00
|
|
|
|
|
|
|
class QuickStartUser(SequentialTaskSet):
|
|
|
|
wait_time = between(0.1,1)
|
|
|
|
|
|
|
|
@task
|
|
|
|
def captcha(self):
|
2021-03-02 11:04:58 -05:00
|
|
|
# TODO: Iterate over parameters for a more comprehensive test
|
|
|
|
captcha_params = {"level":"easy","media":"image/png","input_type":"text"}
|
2021-02-16 05:32:57 -05:00
|
|
|
|
|
|
|
resp = self.client.post(path="/v1/captcha", json=captcha_params, name="/captcha")
|
2020-09-23 13:28:42 -04:00
|
|
|
if resp.status_code != 200:
|
|
|
|
print("\nError on /captcha endpoint: ")
|
|
|
|
print(resp)
|
|
|
|
print(resp.text)
|
2021-03-02 11:04:58 -05:00
|
|
|
print("----------------END.CAPTCHA-------------------\n\n")
|
2021-02-16 05:32:57 -05:00
|
|
|
|
|
|
|
uuid = json.loads(resp.text).get("id")
|
|
|
|
answerBody = {"answer": "qwer123","id": uuid}
|
2020-09-23 13:28:42 -04:00
|
|
|
|
2021-02-16 05:32:57 -05:00
|
|
|
resp = self.client.get(path="/v1/media?id=%s" % uuid, name="/media")
|
2020-09-23 13:28:42 -04:00
|
|
|
if resp.status_code != 200:
|
2021-03-02 11:04:58 -05:00
|
|
|
print("\nError on /media endpoint: ")
|
2020-09-23 13:28:42 -04:00
|
|
|
print(resp)
|
|
|
|
print(resp.text)
|
2021-03-02 11:04:58 -05:00
|
|
|
print("----------------END.MEDIA-------------------\n\n")
|
2020-09-23 13:28:42 -04:00
|
|
|
|
2021-02-16 05:32:57 -05:00
|
|
|
resp = self.client.post(path='/v1/answer', json=answerBody, name="/answer")
|
2020-09-23 13:28:42 -04:00
|
|
|
if resp.status_code != 200:
|
2021-03-02 11:04:58 -05:00
|
|
|
print("\nError on /answer endpoint: ")
|
2020-09-23 13:28:42 -04:00
|
|
|
print(resp)
|
|
|
|
print(resp.text)
|
2021-03-02 11:04:58 -05:00
|
|
|
print("----------------END.ANSWER-------------------\n\n")
|
2020-09-23 13:28:42 -04:00
|
|
|
|
|
|
|
|
|
|
|
class User(FastHttpUser):
|
|
|
|
wait_time = between(0.1,1)
|
|
|
|
tasks = [QuickStartUser]
|
|
|
|
host = "http://localhost:8888"
|