diff --git a/.github/workflows/scala.yml b/.github/workflows/ci.yml similarity index 76% rename from .github/workflows/scala.yml rename to .github/workflows/ci.yml index 8007c8f..b48fcb0 100644 --- a/.github/workflows/scala.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.gitignore b/.gitignore index 822b674..bb826aa 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ .metals .vscode +# for python test env +/testEnv/ + # for various captcha /known/ /unknown/ diff --git a/tests/locustfile.py b/tests/locustfile.py index 54774e0..df55b4c 100644 --- a/tests/locustfile.py +++ b/tests/locustfile.py @@ -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) diff --git a/tests/run.sh b/tests/run.sh new file mode 100755 index 0000000..34ed4fd --- /dev/null +++ b/tests/run.sh @@ -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