From 47106a845909c1c3321b2cb1a0bb59727875c6e9 Mon Sep 17 00:00:00 2001 From: Anton SHEPILOV Date: Mon, 3 Feb 2025 17:12:29 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8FMade=20performance=20test=20r?= =?UTF-8?q?unnable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tdrive/backend/node/test/performance/README.md | 18 ++++++++++++++++++ .../node/test/performance/files/example.js | 15 +++++++++++++++ .../test/performance/files/upload-files.js | 6 ++++-- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 tdrive/backend/node/test/performance/README.md create mode 100644 tdrive/backend/node/test/performance/files/example.js diff --git a/tdrive/backend/node/test/performance/README.md b/tdrive/backend/node/test/performance/README.md new file mode 100644 index 00000000..98ca694a --- /dev/null +++ b/tdrive/backend/node/test/performance/README.md @@ -0,0 +1,18 @@ +# Performance Tests + +## Developer guide + +### Getting started + +1. Install k6 if you want to run it locally or user docker image + +``` +https://grafana.com/docs/k6/latest/set-up/install-k6/ +``` + +2. Run all tests + +```sh +k6 run --vus 10 -e BACKEND=https://tdrive.qa.lin-saas.com -e COMPANY_ID=00000000-0000-4000-0000-000000000000 -e JWT= files/upload-files.js +``` + diff --git a/tdrive/backend/node/test/performance/files/example.js b/tdrive/backend/node/test/performance/files/example.js new file mode 100644 index 00000000..7514ed72 --- /dev/null +++ b/tdrive/backend/node/test/performance/files/example.js @@ -0,0 +1,15 @@ +import http from 'k6/http'; +import { sleep } from 'k6'; + +export const options = { + iterations: 10, +}; + +// The default exported function is gonna be picked up by k6 as the entry point for the test script. It will be executed repeatedly in "iterations" for the whole duration of the test. +export default function () { + // Make a GET request to the target URL + http.get('https://test-api.k6.io'); + + // Sleep for 1 second to simulate real-world usage + sleep(1); +} \ No newline at end of file diff --git a/tdrive/backend/node/test/performance/files/upload-files.js b/tdrive/backend/node/test/performance/files/upload-files.js index d50c09ba..4aabdd54 100644 --- a/tdrive/backend/node/test/performance/files/upload-files.js +++ b/tdrive/backend/node/test/performance/files/upload-files.js @@ -13,7 +13,7 @@ export let options = { { duration: "10s", target: 0 }, ], thresholds: { - upload_duration: ["p(95)<17000"], // 95% of uploads should be faster than 500ms + upload_duration: ["p(95)<500"], // 95% of uploads should be faster than 500ms }, }; @@ -29,7 +29,7 @@ function uploadFile(filePath, fileType, JWT, companyID) { const formData = new FormData(); const randomInt = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); const fileName = `${randomInt.toString(36)}.${fileType.split("/")[1]}`; // Extract extension from MIME type - formData.append("file", http.file(open(filePath), fileName, fileType)); + formData.append("file", http.file(filePath, fileName, fileType)); const headers = { Authorization: `Bearer ${JWT}`, @@ -56,5 +56,7 @@ export default function () { "company_id is present": body => body.resource.company_id !== undefined, }); + + sleep(1); }