Skip to content

Commit bfc55f4

Browse files
authored
Merge pull request #1507 from input-output-hk/test/ws-server-idle-connections
LW-11659 Add wallet idle time to ws-server load test
2 parents 0c3595b + 99fda7b commit bfc55f4

File tree

2 files changed

+49
-12
lines changed

2 files changed

+49
-12
lines changed

.github/workflows/k6-web-socket.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ on:
3636
type: number
3737
required: true
3838
default: 100
39+
wallet-restoration:
40+
description: 'The test will perform wallet restoration procedure.'
41+
type: boolean
42+
connections-seconds:
43+
description: 'Number of seconds to spread the connections.'
44+
type: number
45+
required: true
46+
default: 3
47+
idle-seconds:
48+
description: 'Number of seconds to keep the wallets in idle state before ending the test.'
49+
type: number
50+
required: true
51+
default: 60
3952

4053
jobs:
4154
web-socket:
@@ -67,6 +80,9 @@ jobs:
6780
-e WALLETS=${{ inputs.wallets }}
6881
-e HD_ACTIVE_ADDR_COUNT=${{ inputs.hd-addr-per-wallet }}
6982
-e HD_MAX_TX_HISTORY=${{ inputs.hd-tx-history-size-per-wallet }}
83+
-e WALLET_RESTORATION=${{ inputs.wallet-restoration }}
84+
-e CONNECTIONS_SECONDS=${{ inputs.connections-seconds }}
85+
-e IDLE_SECONDS=${{ inputs.idle-seconds }}
7086
--out json=web-socket-results.json
7187
--quiet
7288
- name: Upload performance test results

packages/e2e/test/k6/scenarios/web-socket.test.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ import { SharedArray } from 'k6/data';
66
import { check } from 'k6';
77
import ws from 'k6/ws';
88

9-
const { HD_ACTIVE_ADDR_COUNT, HD_MAX_TX_HISTORY, TARGET_NET, WALLETS } = Object.assign(
10-
{ HD_ACTIVE_ADDR_COUNT: '10', HD_MAX_TX_HISTORY: '100', TARGET_NET: 'mainnet', WALLETS: '100' },
9+
const parameters = Object.assign(
10+
{
11+
CONNECTIONS_SECONDS: '3',
12+
HD_ACTIVE_ADDR_COUNT: '10',
13+
HD_MAX_TX_HISTORY: '100',
14+
IDLE_SECONDS: '60',
15+
TARGET_NET: 'mainnet',
16+
WALLET_RESTORATION: 'false',
17+
WALLETS: '100'
18+
},
1119
// eslint-disable-next-line no-undef
1220
__ENV
1321
);
@@ -16,9 +24,12 @@ const { HD_ACTIVE_ADDR_COUNT, HD_MAX_TX_HISTORY, TARGET_NET, WALLETS } = Object.
1624
const dut = k6Utils.getDut(__ENV, { networks: ['mainnet', 'preprod'] });
1725
const url = `wss://${dut}/ws`;
1826

19-
const activeAddrCount = Number.parseInt(HD_ACTIVE_ADDR_COUNT, 10);
20-
const maxTxHistory = Number.parseInt(HD_MAX_TX_HISTORY, 10);
21-
const numWallets = Number.parseInt(WALLETS, 10);
27+
const activeAddrCount = Number.parseInt(parameters.HD_ACTIVE_ADDR_COUNT, 10);
28+
const idleSeconds = Number.parseInt(parameters.IDLE_SECONDS, 10);
29+
const connectionsSeconds = Number.parseInt(parameters.CONNECTIONS_SECONDS, 10);
30+
const maxTxHistory = Number.parseInt(parameters.HD_MAX_TX_HISTORY, 10);
31+
const numWallets = Number.parseInt(parameters.WALLETS, 10);
32+
const walletRestoration = parameters.WALLETS === 'true';
2233

2334
export const options = {
2435
ext: {
@@ -31,15 +42,15 @@ export const options = {
3142
connections: {
3243
executor: 'ramping-vus',
3344
gracefulRampDown: '0s',
34-
gracefulStop: '10m',
35-
stages: [{ duration: '3s', target: numWallets }],
45+
gracefulStop: '60m',
46+
stages: [{ duration: `${connectionsSeconds}s`, target: numWallets }],
3647
startVUs: 1
3748
}
3849
}
3950
};
4051

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

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

91+
// eslint-disable-next-line sonarjs/cognitive-complexity
8092
const res = ws.connect(url, null, (socket) => {
93+
let blockNo = 0;
8194
let closed = false;
8295
let requestId = 0;
8396
let transactionsCount = 0;
@@ -92,23 +105,31 @@ export const run = ({ wallets }) => {
92105
return socket.setTimeout(() => {
93106
closed = true;
94107
socket.close();
95-
}, 1000);
108+
}, idleSeconds * 1000);
96109
}
97110

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

103-
socket.send(JSON.stringify({ requestId, txsByAddresses: { addresses: [address], lower: 0 } }));
116+
const lower = walletRestoration ? 0 : blockNo;
117+
118+
socket.send(JSON.stringify({ requestId, txsByAddresses: { addresses: [address], lower } }));
104119
};
105120

106121
socket.on('message', (message) => {
107-
const { clientId, responseTo, transactions } = JSON.parse(message);
122+
const { clientId, networkInfo, responseTo, transactions } = JSON.parse(message);
108123

124+
// Set operational stat
109125
if (clientId) operationalTrend.add(Date.now() - begin);
126+
127+
// Perform init with or without restoration
128+
if (networkInfo) ({ blockNo } = networkInfo.ledgerTip);
110129
if (clientId || responseTo) nextAddress();
111-
if (transactions) transactionsCount += transactions.length;
130+
131+
// Count the incoming transactions
132+
if (Array.isArray(transactions)) transactionsCount += transactions.length;
112133
});
113134

114135
// Count unexpected close

0 commit comments

Comments
 (0)