-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into sessions
- Loading branch information
Showing
10 changed files
with
203 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Project Name | ||
|
||
Load Testing with K6 | ||
|
||
## Table of Contents | ||
|
||
- [Project Description](#project-description) | ||
- [Prerequisites](#prerequisites) | ||
- [Installation](#installation) | ||
- [Getting Started](#getting-started) | ||
- [Usage](#usage) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
|
||
## Project Description | ||
|
||
To set up a load test against the CSMS back-end using a number of simulated charge stations. | ||
|
||
## Prerequisites | ||
1. Ensure that the CSMS backend is running via docker | ||
|
||
## Installation | ||
|
||
1. Install k6 onto your local machine | ||
```bash | ||
brew install k6 | ||
``` | ||
2. Download xk6 using go | ||
```bash | ||
go install go.k6.io/xk6/cmd/xk6@latest | ||
``` | ||
|
||
3. Build the binary | ||
```bash | ||
xk6 build --with github.com/grafana/xk6-dashboard@latest | ||
``` | ||
|
||
## Getting Started | ||
|
||
1. Extract and copy the base64SHA256Password using the following command | ||
```bash | ||
(cd manager && go run main.go auth encode-password fiddlesticks_fishsticks) | ||
``` | ||
2. Register a number of charge stations to the CSMS (e.g. cs1, cs2, cs3 etc). Replace 'BASE64_SHA256_PASSWORD' with the base64SHA256Password that was extracted | ||
```bash | ||
curl http://localhost:9410/api/v0/cs/cs1 -H 'content-type: application/json' -d '{"securityProfile":1,"base64SHA256Password":"BASE64_SHA256_PASSWORD"}' && | ||
curl http://localhost:9410/api/v0/cs/cs2 -H 'content-type: application/json' -d '{"securityProfile":1,"base64SHA256Password":"BASE64_SHA256_PASSWORD"}' && | ||
curl http://localhost:9410/api/v0/cs/cs3 -H 'content-type: application/json' -d '{"securityProfile":1,"base64SHA256Password":"BASE64_SHA256_PASSWORD"}' | ||
``` | ||
|
||
3. Register the contract token to the CSMS | ||
```bash | ||
curl -i http://localhost:9410/api/v0/token -H 'content-type: application/json' -d '{"countryCode": "GB","partyId": "TWK","type": "RFID","uid": "38748383L7337848H823","contractId": "GBTWK012345678V","issuer": "Thoughtworks","valid": true,"cacheMode": "ALWAYS"}' | ||
``` | ||
|
||
4. Set the load simulation for ramping virtual users in loadtests/ws_load_test.js. Please refer to https://k6.io/docs/using-k6/scenarios/executors/ramping-vus/ for guidance. Please note that 1 virtual user is the equivalent to 1 charge station. | ||
|
||
|
||
5. Run the load test using the script file and output the results to the k6 dashboard | ||
```bash | ||
./k6 run --out dashboard loadtests/ws_load_test.js | ||
``` | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import ws from 'k6/ws'; | ||
import { check } from 'k6'; | ||
import encoding from 'k6/encoding'; | ||
import exec from 'k6/execution'; | ||
import { sleep } from 'k6'; | ||
|
||
export const options = { | ||
discardResponseBodies: true, | ||
scenarios: { | ||
contacts: { | ||
executor: 'ramping-vus', | ||
startVUs: 2, | ||
stages: [ | ||
{ duration: '5m', target: 50 }, | ||
{ duration: '5m', target: 100 }, | ||
{ duration: '10m', target: 200 }, | ||
{ duration: '10m', target: 300 }, | ||
{ duration: '10m', target: 400 }, | ||
{ duration: '10m', target: 500 }, | ||
{ duration: '10m', target: 600 }, | ||
{ duration: '5m', target: 550 }, | ||
{ duration: '5m', target: 600 }, | ||
{ duration: '5m', target: 550 }, | ||
{ duration: '5m', target: 600 }, | ||
{ duration: '10m', target: 500 }, | ||
{ duration: '10m', target: 400 }, | ||
{ duration: '10m', target: 300 }, | ||
{ duration: '10m', target: 100 }, | ||
{ duration: '5m', target: 50 }, | ||
{ duration: '5m', target: 0 } | ||
], | ||
gracefulRampDown: '0s', | ||
}, | ||
}, | ||
}; | ||
|
||
export default function () { | ||
let vuIdInTest = exec.vu.idInTest | ||
let data = `cs${vuIdInTest}:fiddlesticks_fishsticks`; | ||
let base64data = encoding.b64encode(data) | ||
const params = { | ||
headers: {'Sec-WebSocket-Protocol': 'ocpp1.6', 'Authorization': `Basic ${base64data}`} | ||
}; | ||
const url = `ws://localhost/ws/cs${vuIdInTest}`; | ||
const res = ws.connect(url, params, function (socket) { | ||
socket.send('[2,"1","BootNotification",{"chargePointModel":"me100","chargePointVendor":"me"}]'); | ||
sleep(10) | ||
socket.send('[2,"2", "StatusNotification", {"connectorId": 1, "errorCode": "NoError", "status": "Available"}]'); | ||
sleep(10) | ||
socket.send('[2,"3","Heartbeat", {}]'); | ||
sleep(10) | ||
socket.send('[2,"4","Heartbeat", {}]'); | ||
sleep(10) | ||
socket.send('[2,"5","Heartbeat", {}]'); | ||
sleep(10) | ||
socket.send('[2, "6", "Authorize", {"idTag": "38748383L7337848H823"}]'); | ||
sleep(10) | ||
socket.send('[2,"7", "StatusNotification", {"connectorId": 1, "errorCode": "NoError", "status": "Preparing"}]'); | ||
sleep(10) | ||
socket.send('[2,"8", "StartTransaction",{"connectorId": 1, "idTag": "38748383L7337848H823", "meterStart": 3, "reservationId": 5, "timestamp":"2023-09-18T08:25:40.20Z"}]'); | ||
sleep(300) | ||
socket.send('[2,"9","Heartbeat", {}]'); | ||
sleep(60) | ||
socket.send('[2,"10","Heartbeat", {}]'); | ||
sleep(60) | ||
socket.send('[2,"11","Heartbeat", {}]'); | ||
sleep(60) | ||
sleep(300) | ||
socket.send('[2,"12", "MeterValues", {"connectorId": 1, "meterValue":[{"timestamp":"2023-09-18T08:25:40.20Z", "sampledValue": [{"value": "5"}]}]}]'); | ||
sleep(60) | ||
socket.send('[2,"13", "MeterValues", {"connectorId": 1, "meterValue":[{"timestamp":"2023-09-18T08:25:40.20Z", "sampledValue": [{"value": "5"}]}]}]'); | ||
sleep(60) | ||
socket.send('[2,"14", "StopTransaction", {"idTag": "38748383L7337848H823", "meterStop": 3, "timestamp": "2023-09-18T08:25:40.20Z", "transactionId": 3}]'); | ||
sleep(10) | ||
socket.send('[2,"15", "StatusNotification", {"connectorId": 1, "errorCode": "NoError", "status": "Finishing"}]'); | ||
sleep(10) | ||
socket.send('[2,"16", "StatusNotification", {"connectorId": 1, "errorCode": "NoError", "status": "Available"}]'); | ||
sleep(10) | ||
socket.close() | ||
} | ||
); | ||
|
||
check(res, { 'status is 101': (r) => r && r.status === 101 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
global: | ||
scrape_interval: 15s | ||
|
||
scrape_configs: | ||
- job_name: 'prometheus' | ||
static_configs: | ||
- targets: [ 'host.docker.internal:9090' ] | ||
- job_name: 'endpoints' | ||
static_configs: | ||
- targets: ['gateway:9312', 'manager:9410'] | ||
|