Skip to content

Commit

Permalink
feat: add web socket server load tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iccicci committed Jul 15, 2024
1 parent cd0dcad commit 8c28f7c
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/k6-web-socket.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,53 @@ name: K6 WebSocket server load tests

on:
workflow_dispatch:
branches: ['master', 'feat/web-socket-network-info-provider']
inputs:
environment:
description: 'Target environment'
type: choice
required: true
options:
- 'dev'
- 'ops'
- 'staging'
- 'prod'
network:
description: 'Target network'
type: choice
required: true
options:
- 'preview'
- 'preprod'
- 'sanchonet'
- 'mainnet'
wallets:
description: 'Number of wallets to simulate'
type: number
required: true
default: 1000

jobs:
web-socket:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Run k6 cloud test
uses: grafana/k6-action@v0.3.1
env:
K6_CLOUD_PROJECT_ID: ${{ secrets.K6_CLOUD_PROJECT_ID }}
with:
filename: ./packages/e2e/test/k6/scenarios/web-socket.test.js
cloud: false
token: ${{ secrets.K6_CLOUD_API_TOKEN }}
flags: >
-e TARGET_ENV=${{ inputs.environment }}
-e TARGET_NET=${{ inputs.network }}
-e WALLETS=${{ inputs.wallets }}
--out json=web-socket-results.json
- name: Upload performance test results
uses: actions/upload-artifact@v3
with:
name: k6-report
path: web-socket-results.json
64 changes: 64 additions & 0 deletions packages/e2e/test/k6/scenarios/web-socket.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// cSpell:ignore loadimpact

import { Counter, Trend } from 'k6/metrics';
import { check } from 'k6';
import ws from 'k6/ws';

// eslint-disable-next-line no-undef
const { TARGET_ENV, TARGET_NET, WALLETS } = __ENV;
const url = `wss://${TARGET_ENV}-${TARGET_NET}${TARGET_ENV === 'ops' ? '-1' : ''}.lw.iog.io/`;

export const options = {
ext: {
loadimpact: {
apm: [],
distribution: { 'amazon:us:portland': { loadZone: 'amazon:us:portland', percent: 100 } }
}
},
scenarios: {
connections: {
executor: 'ramping-vus',
gracefulRampDown: '0s',
gracefulStop: '120s',
stages: [{ duration: '3s', target: Number.parseInt(WALLETS, 10) }],
startVUs: 10
}
}
};

const operationalTrend = new Trend('_operational', true);
const unexpectedCloseCounter = new Counter('_unexpected_close');

export const run = () => {
const begin = Date.now();

const res = ws.connect(url, null, (socket) => {
let closed = false;
let firstMessage = true;

socket.on('message', () => {
if (firstMessage) {
operationalTrend.add(Date.now() - begin);
firstMessage = false;
}
});

// Count unexpected close
socket.on('close', () => {
if (!closed) unexpectedCloseCounter.add(1);
});

// Heartbeat
socket.setTimeout(() => socket.send('{}'), 30 * 1000);

// End the test after 80"
socket.setTimeout(() => {
closed = true;
socket.close();
}, 80 * 1000);
});

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

export default run;

0 comments on commit 8c28f7c

Please sign in to comment.