From a241c08fc3332cba26ed67e25dc576284b0c45a5 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Sun, 2 Apr 2023 21:25:46 +0800 Subject: [PATCH] test: add loadtest --- Makefile | 3 +++ tests/default.loadtest.js | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/default.loadtest.js diff --git a/Makefile b/Makefile index 05963fb..bd1079b 100644 --- a/Makefile +++ b/Makefile @@ -21,3 +21,6 @@ setup-development-environment: install-poetry $(PRE_COMMIT_HOOK) test-smoke: k6 run tests/*.smoke.js + +test-loadtest: + k6 run tests/*.loadtest.js diff --git a/tests/default.loadtest.js b/tests/default.loadtest.js new file mode 100644 index 0000000..2721205 --- /dev/null +++ b/tests/default.loadtest.js @@ -0,0 +1,25 @@ +import http from 'k6/http'; +import { check, group, sleep } from 'k6'; + +export const options = { + stages: [ + { duration: '5s', target: 10 }, // simulate ramp-up of traffic from 1 to 10 users over 30s. + { duration: '30s', target: 10 }, // stay at 10 users for 10 minutes + { duration: '5s', target: 0 }, // ramp-down to 0 users + ], + thresholds: { + 'http_req_duration': ['p(99)<1000'], // 99% of requests must complete below 1000ms + }, +}; + +export default () => { + const payload = JSON.stringify({ + prompt: "def binarySearch(arr, left, right, x):\n mid = (left +", + }); + const headers = { "Content-Type": "application/json" }; + const res = http.post("http://localhost:5000/v1/completions", payload, { + headers, + }); + check(res, { success: (r) => r.status === 200 }); + sleep(0.5); +};