Skip to content

Commit

Permalink
[US] Changed the websocket protocol for load test
Browse files Browse the repository at this point in the history
  • Loading branch information
usuletw022 committed Sep 22, 2023
1 parent f0ff32e commit b1e532e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions loadtests/ws_load_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import ws from 'k6/ws';
import { check } from 'k6';
export const options = {
duration: '10s',
vus: 1
};

export default function () {
const url = 'ws://localhost/ws/cs001';
const params = {
headers: {'Sec-WebSocket-Protocol': 'ocpp1.6', 'Authorization': 'Basic Y3MwMDE6ZmlkZGxlc3RpY2tzX2Zpc2hzdGlja3M='}
};


const res = ws.connect(url, params, function (socket) {
socket.on('open', () => console.log('connected'));
socket.on('message', () => console.log('Message received: ', '[2,"9","BootNotification",{"chargePointModel":"me100","chargePointVendor":"me"}]'));
socket.on('message', () => console.log('Message received: ', '[2, "10", "StatusNotification", {"connectorId": 1, "errorCode": "NoError", "status": "Available"}]'));
socket.on('message', () => console.log('Message received: ', '[2,"11","Heartbeat", {}]'));
socket.on('message', () => console.log('Message received: ', '[2,"12","Heartbeat", {}]'));
socket.on('message', () => console.log('Message received: ', '[2,"13","Heartbeat", {}]'));
socket.on('message', () => console.log('Message received: ', '[2, "14", "[2, "16", "Authorize", {"idTag": "38748383L7337848H823"}]'));
socket.on('message', () => console.log('Message received: ', '[2, "15", "StartTransaction",{"connectorId": 1, "idTag": "38748383L7337848H823", "meterStart": 3, "reservationId": 5, "timestamp":"2023-09-18T08:25:40.20Z"}]'));
socket.on('message', () => console.log('Message received: ', '[2, "16", "MeterValues", {"connectorId": 1, "meterValue":[{"timestamp":"2023-09-18T08:25:40.20Z", "sampledValue": [{"value": "5"}]}]}]'));
socket.on('message', () => console.log('Message received: ', '[2, "17", "MeterValues", {"connectorId": 1, "meterValue":[{"timestamp":"2023-09-18T08:25:40.20Z", "sampledValue": [{"value": "5"}]}]}]'));
socket.on('message', () => console.log('Message received: ', '[2, "18", "StopTransaction", {"idTag": "38748383L7337848H823", "meterStop": 3, "timestamp": "2023-09-18T08:25:40.20Z", "transactionId": 3}]'));
socket.on('close', () => console.log('disconnected'));
});

check(res, { 'status is 101': (r) => r && r.status === 101 });
}

0 comments on commit b1e532e

Please sign in to comment.