From 8ce504a5935ddeae64dc8e1bec58503613bc7dbf Mon Sep 17 00:00:00 2001 From: aardouin Date: Fri, 4 Oct 2024 10:32:54 +0200 Subject: [PATCH 1/2] feat(test) #1 Ajout d'un test de charge --- misc/k6/README.md | 9 ++++++++ misc/k6/TestChallenge.js | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 misc/k6/README.md create mode 100644 misc/k6/TestChallenge.js diff --git a/misc/k6/README.md b/misc/k6/README.md new file mode 100644 index 0000000..fe4491f --- /dev/null +++ b/misc/k6/README.md @@ -0,0 +1,9 @@ +# K6 - Load Test + +Very basic load testing script for [k6](https://k6.io/). + +## How to run + +```shell +k6 run -e LOAD_TEST_URL={altcha-api-url} TestChallenge.js +``` diff --git a/misc/k6/TestChallenge.js b/misc/k6/TestChallenge.js new file mode 100644 index 0000000..c43b602 --- /dev/null +++ b/misc/k6/TestChallenge.js @@ -0,0 +1,50 @@ +import { check, group } from 'k6'; +import http from 'k6/http' + +export const options = { + scenarios: { + load: { + vus: 1, + iterations: 1, + executor: 'per-vu-iterations', + options: { + browser: { + type: 'chromium', + }, + }, + }, + } +}; + +http.setResponseCallback( + http.expectedStatuses(200) +); + +export default function () { + + let response; + + group('Request challenge', function () { + + response = http.get(`${__ENV.LOAD_TEST_URL}request`); + check(response, { + 'is status 200': (r) => r.status === 200, + 'Contenu souhaité': r => r.body.includes('algorithm') && r.body.includes('challenge') && r.body.includes('maxNumber') && r.body.includes('salt') && r.body.includes('signature'), + }); + + }) + + group('Verify challenge', function () { + + const data = {"challenge":"d5656d52c5eadce5117024fbcafc706aad397c7befa17804d73c992d966012a8","salt":"8ec1b7ed694331baeb7416d9?expires=1727963398","signature":"781014d0a7ace7e7ae9d12e2d5c0204b60a8dbf42daa352ab40ab582b03a9dc6","number":219718,}; + response = http.post(`${__ENV.LOAD_TEST_URL}verify`, JSON.stringify(data), + { + headers: { 'Content-Type': 'application/json' }, + }); + check(response, { + 'is status 200': (r) => r.status === 200, + 'Challenge verified': (r) => r.body.includes('true'), + }); + + }) +} \ No newline at end of file -- 2.17.1 From 082ab9a7eacc2c42f19849a2cdfe9fbffb4336a8 Mon Sep 17 00:00:00 2001 From: aardouin Date: Fri, 4 Oct 2024 11:11:49 +0200 Subject: [PATCH 2/2] fix(test) #1 Correction scenario --- misc/k6/TestChallenge.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/misc/k6/TestChallenge.js b/misc/k6/TestChallenge.js index c43b602..ea34250 100644 --- a/misc/k6/TestChallenge.js +++ b/misc/k6/TestChallenge.js @@ -4,8 +4,8 @@ import http from 'k6/http' export const options = { scenarios: { load: { - vus: 1, - iterations: 1, + vus: 10, + iterations: 10, executor: 'per-vu-iterations', options: { browser: { -- 2.17.1