mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-04-18 17:55:18 -04:00
run functional test
Signed-off-by: hrj <harshad.rj@gmail.com>
This commit is contained in:
parent
d9fefca841
commit
3cfba7a08e
68
tests/locustfile-functional.py
Normal file
68
tests/locustfile-functional.py
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
from locust import task, between, SequentialTaskSet
|
||||||
|
from locust.contrib.fasthttp import FastHttpUser
|
||||||
|
from locust import events
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
@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
|
||||||
|
|
||||||
|
class QuickStartUser(SequentialTaskSet):
|
||||||
|
wait_time = between(0.1,0.2)
|
||||||
|
|
||||||
|
@task
|
||||||
|
def captcha(self):
|
||||||
|
# TODO: Iterate over parameters for a more comprehensive test
|
||||||
|
captcha_params = {"level":"debug","media":"image/png","input_type":"text"}
|
||||||
|
|
||||||
|
resp = self.client.post(path="/v1/captcha", json=captcha_params, name="/captcha")
|
||||||
|
if resp.status_code != 200:
|
||||||
|
print("\nError on /captcha endpoint: ")
|
||||||
|
print(resp)
|
||||||
|
print(resp.text)
|
||||||
|
print("----------------END.CAPTCHA-------------------\n\n")
|
||||||
|
|
||||||
|
uuid = resp.json().get("id")
|
||||||
|
|
||||||
|
resp = self.client.get(path="/v1/media?id=%s" % uuid, name="/media", stream=True)
|
||||||
|
if resp.status_code != 200:
|
||||||
|
print("\nError on /media endpoint: ")
|
||||||
|
print(resp)
|
||||||
|
print(resp.text)
|
||||||
|
print("----------------END.MEDIA-------------------\n\n")
|
||||||
|
|
||||||
|
media = resp.content
|
||||||
|
mediaFileName = "tests/test-%s.png" % uuid
|
||||||
|
with open(mediaFileName, "wb") as f:
|
||||||
|
f.write(media)
|
||||||
|
ocrResult = subprocess.Popen("gocr %s" % mediaFileName, shell=True, stdout=subprocess.PIPE)
|
||||||
|
ocrAnswer = ocrResult.stdout.readlines()[0].strip().decode()
|
||||||
|
|
||||||
|
answerBody = {"answer": ocrAnswer,"id": uuid}
|
||||||
|
with self.client.post(path='/v1/answer', json=answerBody, name="/answer", catch_response=True) as resp:
|
||||||
|
if resp.status_code != 200:
|
||||||
|
print("\nError on /answer endpoint: ")
|
||||||
|
print(resp)
|
||||||
|
print(resp.text)
|
||||||
|
print("----------------END.ANSWER-------------------\n\n")
|
||||||
|
else:
|
||||||
|
if resp.json().get("result") != "True":
|
||||||
|
resp.failure("Answer was not accepted")
|
||||||
|
|
||||||
|
|
||||||
|
class User(FastHttpUser):
|
||||||
|
wait_time = between(0.1,0.2)
|
||||||
|
tasks = [QuickStartUser]
|
||||||
|
host = "http://localhost:8888"
|
10
tests/run.sh
10
tests/run.sh
@ -10,6 +10,14 @@ sleep 4
|
|||||||
locust --headless -u 300 -r 100 --run-time 4m --stop-timeout 30 -f tests/locustfile.py
|
locust --headless -u 300 -r 100 --run-time 4m --stop-timeout 30 -f tests/locustfile.py
|
||||||
status=$?
|
status=$?
|
||||||
|
|
||||||
kill $JAVA_PID
|
if [ $status != 0 ]; then
|
||||||
|
kill $JAVA_PID
|
||||||
|
exit $status
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo Run functional test
|
||||||
|
locust --headless -u 1 -r 1 --run-time 1m --stop-timeout 30 -f tests/locustfile-functional.py
|
||||||
|
status=$?
|
||||||
|
|
||||||
|
kill $JAVA_PID
|
||||||
exit $status
|
exit $status
|
||||||
|
Loading…
x
Reference in New Issue
Block a user