Merge pull request #72 from UprootStaging/testing

Run locust tests in CI
This commit is contained in:
hrj 2021-04-02 18:37:23 +05:30 committed by GitHub
commit 02e9115641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 3 deletions

View File

@ -1,8 +1,7 @@
name: Scala CI
name: Core CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
@ -18,6 +17,8 @@ jobs:
with:
java-version: 1.11
- name: Run tests
run: sbt test
run: sbt test assembly
- name: Run linter
run: sbt "scalafixAll --check"
- name: Run locust tests
run: ./tests/run.sh

3
.gitignore vendored
View File

@ -9,6 +9,9 @@
.metals
.vscode
# for python test env
/testEnv/
# for various captcha
/known/
/unknown/

View File

@ -1,6 +1,22 @@
from locust import task, between, SequentialTaskSet
from locust.contrib.fasthttp import FastHttpUser
from locust import events
import json
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
class QuickStartUser(SequentialTaskSet):
wait_time = between(0.1,1)

15
tests/run.sh Executable file
View File

@ -0,0 +1,15 @@
set -ex
python3 -m venv testEnv
source ./testEnv/bin/activate
pip install locust
java -jar target/scala-2.13/LibreCaptcha.jar &
JAVA_PID=$!
sleep 4
locust --headless -u 1000 -r 100 --run-time 4m --stop-timeout 30 -f tests/locustfile.py
status=$?
kill $JAVA_PID
exit $status