Skip to content
Merged
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
16 changes: 16 additions & 0 deletions .github/workflows/k6-web-socket.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ on:
type: number
required: true
default: 100
wallet-restoration:
description: 'The test will perform wallet restoration procedure.'
type: boolean
connections-seconds:
description: 'Number of seconds to spread the connections.'
type: number
required: true
default: 3
idle-seconds:
description: 'Number of seconds to keep the wallets in idle state before ending the test.'
type: number
required: true
default: 60

jobs:
web-socket:
Expand Down Expand Up @@ -67,6 +80,9 @@ jobs:
-e WALLETS=${{ inputs.wallets }}
-e HD_ACTIVE_ADDR_COUNT=${{ inputs.hd-addr-per-wallet }}
-e HD_MAX_TX_HISTORY=${{ inputs.hd-tx-history-size-per-wallet }}
-e WALLET_RESTORATION=${{ inputs.wallet-restoration }}
-e CONNECTIONS_SECONDS=${{ inputs.connections-seconds }}
-e IDLE_SECONDS=${{ inputs.idle-seconds }}
--out json=web-socket-results.json
--quiet
- name: Upload performance test results
Expand Down
45 changes: 33 additions & 12 deletions packages/e2e/test/k6/scenarios/web-socket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ import { SharedArray } from 'k6/data';
import { check } from 'k6';
import ws from 'k6/ws';

const { HD_ACTIVE_ADDR_COUNT, HD_MAX_TX_HISTORY, TARGET_NET, WALLETS } = Object.assign(
{ HD_ACTIVE_ADDR_COUNT: '10', HD_MAX_TX_HISTORY: '100', TARGET_NET: 'mainnet', WALLETS: '100' },
const parameters = Object.assign(
{
CONNECTIONS_SECONDS: '3',
HD_ACTIVE_ADDR_COUNT: '10',
HD_MAX_TX_HISTORY: '100',
IDLE_SECONDS: '60',
TARGET_NET: 'mainnet',
WALLET_RESTORATION: 'false',
WALLETS: '100'
},
// eslint-disable-next-line no-undef
__ENV
);
Expand All @@ -16,9 +24,12 @@ const { HD_ACTIVE_ADDR_COUNT, HD_MAX_TX_HISTORY, TARGET_NET, WALLETS } = Object.
const dut = k6Utils.getDut(__ENV, { networks: ['mainnet', 'preprod'] });
const url = `wss://${dut}/ws`;

const activeAddrCount = Number.parseInt(HD_ACTIVE_ADDR_COUNT, 10);
const maxTxHistory = Number.parseInt(HD_MAX_TX_HISTORY, 10);
const numWallets = Number.parseInt(WALLETS, 10);
const activeAddrCount = Number.parseInt(parameters.HD_ACTIVE_ADDR_COUNT, 10);
const idleSeconds = Number.parseInt(parameters.IDLE_SECONDS, 10);
const connectionsSeconds = Number.parseInt(parameters.CONNECTIONS_SECONDS, 10);
const maxTxHistory = Number.parseInt(parameters.HD_MAX_TX_HISTORY, 10);
const numWallets = Number.parseInt(parameters.WALLETS, 10);
const walletRestoration = parameters.WALLETS === 'true';

export const options = {
ext: {
Expand All @@ -31,15 +42,15 @@ export const options = {
connections: {
executor: 'ramping-vus',
gracefulRampDown: '0s',
gracefulStop: '10m',
stages: [{ duration: '3s', target: numWallets }],
gracefulStop: '60m',
stages: [{ duration: `${connectionsSeconds}s`, target: numWallets }],
startVUs: 1
}
}
};

/** Wallet addresses extracted from the JSON dump file */
const fileName = `../../dump/addresses/${TARGET_NET}.json`;
const fileName = `../../dump/addresses/${parameters.TARGET_NET}.json`;
// eslint-disable-next-line no-undef
const walletsOrig = new SharedArray('walletsData', () => JSON.parse(open(fileName)));

Expand Down Expand Up @@ -77,7 +88,9 @@ export const run = ({ wallets }) => {
const vu = __VU;
const wallet = wallets[vu % wallets.length]; // each wallet is a collection of addresses

// eslint-disable-next-line sonarjs/cognitive-complexity
const res = ws.connect(url, null, (socket) => {
let blockNo = 0;
let closed = false;
let requestId = 0;
let transactionsCount = 0;
Expand All @@ -92,23 +105,31 @@ export const run = ({ wallets }) => {
return socket.setTimeout(() => {
closed = true;
socket.close();
}, 1000);
}, idleSeconds * 1000);
}

const address =
requestId <= wallet.length
? wallet[requestId - 1].address
: getDummyAddr(wallet[0].address, requestId - wallet.length);

socket.send(JSON.stringify({ requestId, txsByAddresses: { addresses: [address], lower: 0 } }));
const lower = walletRestoration ? 0 : blockNo;

socket.send(JSON.stringify({ requestId, txsByAddresses: { addresses: [address], lower } }));
};

socket.on('message', (message) => {
const { clientId, responseTo, transactions } = JSON.parse(message);
const { clientId, networkInfo, responseTo, transactions } = JSON.parse(message);

// Set operational stat
if (clientId) operationalTrend.add(Date.now() - begin);

// Perform init with or without restoration
if (networkInfo) ({ blockNo } = networkInfo.ledgerTip);
if (clientId || responseTo) nextAddress();
if (transactions) transactionsCount += transactions.length;

// Count the incoming transactions
if (Array.isArray(transactions)) transactionsCount += transactions.length;
});

// Count unexpected close
Expand Down
Loading