Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions green_metric_tests/greencheck_api_loadtest.js
Original file line number Diff line number Diff line change
@@ -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,
});
}


19 changes: 19 additions & 0 deletions usage_scenario.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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