From 5aad8d21354412e96a3cb32eae0ff5ec99f04117 Mon Sep 17 00:00:00 2001 From: hrj Date: Fri, 2 Apr 2021 15:32:37 +0530 Subject: [PATCH 01/11] run CI for all branches --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b8e09aa --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,22 @@ +name: Core CI + +on: + push + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.11 + uses: actions/setup-java@v1 + with: + java-version: 1.11 + - name: Run tests + run: sbt test + - name: Run linter + run: sbt "scalafixAll --check" From e9ff454be5ac708d412123f9028a726dcd21a409 Mon Sep 17 00:00:00 2001 From: hrj Date: Fri, 2 Apr 2021 15:34:05 +0530 Subject: [PATCH 02/11] fix syntax error --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8e09aa..7e99d29 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ name: Core CI on: - push + push: pull_request: branches: [ master ] From 19fc5f98f91590783e72dd7e3aaf8e706b787d4d Mon Sep 17 00:00:00 2001 From: hrj Date: Fri, 2 Apr 2021 15:35:40 +0530 Subject: [PATCH 03/11] removed older ci file --- .github/workflows/scala.yml | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 .github/workflows/scala.yml diff --git a/.github/workflows/scala.yml b/.github/workflows/scala.yml deleted file mode 100644 index 8007c8f..0000000 --- a/.github/workflows/scala.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Scala CI - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.11 - uses: actions/setup-java@v1 - with: - java-version: 1.11 - - name: Run tests - run: sbt test - - name: Run linter - run: sbt "scalafixAll --check" From 72f092e6b56d0454ad933021029b9241f683ac11 Mon Sep 17 00:00:00 2001 From: hrj Date: Fri, 2 Apr 2021 15:35:52 +0530 Subject: [PATCH 04/11] run sbt assembly in CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e99d29..1b3f3e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,6 @@ jobs: with: java-version: 1.11 - name: Run tests - run: sbt test + run: sbt test assembly - name: Run linter run: sbt "scalafixAll --check" From 6ea5691c5ea86daad75e76a00e122a2c859b4596 Mon Sep 17 00:00:00 2001 From: hrj Date: Fri, 2 Apr 2021 15:42:47 +0530 Subject: [PATCH 05/11] run locust tests in CI --- .github/workflows/ci.yml | 2 ++ .gitignore | 3 +++ tests/run.sh | 10 ++++++++++ 3 files changed, 15 insertions(+) create mode 100755 tests/run.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b3f3e1..b48fcb0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,3 +20,5 @@ jobs: 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/run.sh b/tests/run.sh new file mode 100755 index 0000000..f216b78 --- /dev/null +++ b/tests/run.sh @@ -0,0 +1,10 @@ +python3 -m venv testEnv +source ./testEnv/activate +pip install locust +java -jar target/scala-2.13/LibreCaptcha.jar & +JAVA_PID=$! +sleep 4 + +locust -f tests/locustfile.py + +kill $JAVA_PID From e79da3b8811e19f334d994fe046b8c7ddb572d93 Mon Sep 17 00:00:00 2001 From: hrj Date: Fri, 2 Apr 2021 15:48:09 +0530 Subject: [PATCH 06/11] start locust in headless mode --- tests/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run.sh b/tests/run.sh index f216b78..988b5e9 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -5,6 +5,6 @@ java -jar target/scala-2.13/LibreCaptcha.jar & JAVA_PID=$! sleep 4 -locust -f tests/locustfile.py +locust --headless -u 1000 -r 100 -f tests/locustfile.py kill $JAVA_PID From f02eadb945cb94d6344a5f52faac2ec15bf1057f Mon Sep 17 00:00:00 2001 From: hrj Date: Fri, 2 Apr 2021 15:51:55 +0530 Subject: [PATCH 07/11] specify run time of locust tests --- tests/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run.sh b/tests/run.sh index 988b5e9..0eebb9b 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -5,6 +5,6 @@ java -jar target/scala-2.13/LibreCaptcha.jar & JAVA_PID=$! sleep 4 -locust --headless -u 1000 -r 100 -f tests/locustfile.py +locust --headless -u 1000 -r 100 --run-time 4m --stop-timeout 30 -f tests/locustfile.py kill $JAVA_PID From 5226e0032edb45c13c7676803a4f64cb584cb4fe Mon Sep 17 00:00:00 2001 From: hrj Date: Fri, 2 Apr 2021 16:17:07 +0530 Subject: [PATCH 08/11] check for failure rate in locust test --- tests/locustfile.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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) From 30f5705aa51c4e25d88d84d3526ae0f68e35e9a3 Mon Sep 17 00:00:00 2001 From: hrj Date: Fri, 2 Apr 2021 16:41:33 +0530 Subject: [PATCH 09/11] exit test script with locust's exit code --- tests/run.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/run.sh b/tests/run.sh index 0eebb9b..da76e76 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -6,5 +6,8 @@ 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 From c9abe141eced4c042af1becd37794c4d20ef89b4 Mon Sep 17 00:00:00 2001 From: hrj Date: Fri, 2 Apr 2021 16:42:00 +0530 Subject: [PATCH 10/11] fail early in test script --- tests/run.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/run.sh b/tests/run.sh index da76e76..4af00ce 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -1,3 +1,5 @@ +set -ex + python3 -m venv testEnv source ./testEnv/activate pip install locust From 7e87f6721b5470144fd7fbc505d36793bc27f033 Mon Sep 17 00:00:00 2001 From: hrj Date: Fri, 2 Apr 2021 16:51:48 +0530 Subject: [PATCH 11/11] test script: fix path to activate --- tests/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run.sh b/tests/run.sh index 4af00ce..34ed4fd 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -1,7 +1,7 @@ set -ex python3 -m venv testEnv -source ./testEnv/activate +source ./testEnv/bin/activate pip install locust java -jar target/scala-2.13/LibreCaptcha.jar & JAVA_PID=$!