diff --git a/green_metric_tests/greencheck_api_loadtest.js b/green_metric_tests/greencheck_api_loadtest.js new file mode 100644 index 00000000..9cd9a7a7 --- /dev/null +++ b/green_metric_tests/greencheck_api_loadtest.js @@ -0,0 +1,32 @@ +// import necessary modules +import { check } from "k6"; +import http from "k6/http"; + +// define configuration +export const options = { + // define thresholds + thresholds: { + http_req_failed: ['rate<0.01'], // http errors should be less than 1% + http_req_duration: ["p(99)<1000"], // 99% of requests should be below 1s + }, +}; + +export default function () { + // define URL and request body + const url = "https://django:9000/api/v3/greencheck/climateaction.tech"; + const params = { + headers: { + "Content-Type": "application/json", + }, + }; + + // send a post request and save response as a variable + const res = http.get(url, params); + + // check that response is 200 + check(res, { + "response code was 200": (res) => res.status == 200, + }); +} + + diff --git a/usage_scenario.yml b/usage_scenario.yml index cd95dff0..5795c960 100644 --- a/usage_scenario.yml +++ b/usage_scenario.yml @@ -86,6 +86,16 @@ services: networks: - greencheck-network + load-test-container: + container_name: load-test-container + image: grafana/k6 + depends_on: + - django + setup-commands: + - cp /tmp/repo/green_metric_tests/greencheck_api_loadtest.js . + networks: + - greencheck-network + flow: # this should trigger a http request to an API endpoint # of http://django:9000, simulating a greencheck lookup @@ -104,3 +114,12 @@ flow: - type: console command: npm test note: Starting test again + - name: Greencheck API Load Test + container: load-test-container + commands: + - type: console + note: Starting load test + read-notes-stdout: true + log-stdout: true + log-stderr: true + command: k6 run --iterations 10 greencheck-api-loadtest.js