Skip to content

Commit

Permalink
fix: Wrong metrics in the report of the WS performance tests (#3193)
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Yanev <[email protected]>
  • Loading branch information
victor-yanev authored Oct 31, 2024
1 parent 976866b commit dfcb7cf
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
5 changes: 4 additions & 1 deletion k6/src/scenarios/test-ws/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import ws from 'k6/ws';
import { check } from 'k6';
import { scenarioDurationGauge } from './index.js';

const errorField = 'error';
const resultField = 'result';
Expand All @@ -37,9 +38,10 @@ function getPayLoad(methodName, paramInput = []) {
});
}

function connectToWebSocket(url, methodName, params = [], responseChecks = {}) {
function connectToWebSocket(url, methodName, scenarioName, params = [], responseChecks = {}) {
return ws.connect(url, {}, (socket) => {
socket.on('open', () => {
const startTime = Date.now();
const message = getPayLoad(methodName, params);
if (isDebugMode) {
console.log('Connected, sending request: ' + message);
Expand All @@ -48,6 +50,7 @@ function connectToWebSocket(url, methodName, params = [], responseChecks = {}) {

socket.on('message', (message) => {
check(message, responseChecks);
scenarioDurationGauge.add(Date.now() - startTime, { scenario: scenarioName });
socket.close();
});
});
Expand Down
4 changes: 3 additions & 1 deletion k6/src/scenarios/test-ws/eth_chainId.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ import { connectToWebSocket, isNonErrorResponse } from './common.js';

const url = __ENV.WS_RELAY_BASE_URL;
const methodName = 'eth_chainId';
const scenarioName = methodName;

const { options, run } = new TestScenarioBuilder()
.name(methodName) // use unique scenario name among all tests
.name(scenarioName) // use unique scenario name among all tests
.request(() => connectToWebSocket(
url,
methodName,
scenarioName,
[],
{ methodName: (r) => isNonErrorResponse(r) }
))
Expand Down
4 changes: 3 additions & 1 deletion k6/src/scenarios/test-ws/eth_subscribe_logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ import { connectToWebSocket, isNonErrorResponse } from './common.js';

const url = __ENV.WS_RELAY_BASE_URL;
const methodName = 'eth_subscribe';
const scenarioName = methodName + '_logs';

const { options, run } = new TestScenarioBuilder()
.name(methodName + '_logs') // use unique scenario name among all tests
.name(scenarioName) // use unique scenario name among all tests
.request((testParameters) => {
return connectToWebSocket(
url,
methodName,
scenarioName,
[subscribeEvents.logs, { address: testParameters.contractsAddresses[0] }],
{ methodName: (r) => isNonErrorResponse(r) }
);
Expand Down
4 changes: 3 additions & 1 deletion k6/src/scenarios/test-ws/eth_subscribe_newHeads.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import { connectToWebSocket, isNonErrorResponse } from './common.js';

const url = __ENV.WS_RELAY_BASE_URL;
const methodName = 'eth_subscribe';
const scenarioName = methodName + '_newHeads';

const { options, run } = new TestScenarioBuilder()
.name(methodName + '_newHeads') // use unique scenario name among all tests
.name(scenarioName) // use unique scenario name among all tests
.request(() => connectToWebSocket(
url,
methodName,
scenarioName,
[subscribeEvents.newHeads],
{ methodName: (r) => isNonErrorResponse(r) }
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import { connectToWebSocket, isErrorResponse } from './common.js';

const url = __ENV.WS_RELAY_BASE_URL;
const methodName = 'eth_subscribe';
const scenarioName = methodName + '_newPendingTransactions';

const { options, run } = new TestScenarioBuilder()
.name(methodName + '_newPendingTransactions') // use unique scenario name among all tests
.request(() => connectToWebSocket(
url,
methodName,
scenarioName,
[subscribeEvents.newPendingTransactions],
{ methodName: (r) => isErrorResponse(r) }
))
Expand Down
3 changes: 1 addition & 2 deletions k6/src/scenarios/ws-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.1/index.js';

import { markdownReport } from '../lib/common.js';
import { setupTestParameters } from '../lib/bootstrapEnvParameters.js';
import { funcs, options, scenarioDurationGauge } from './test-ws/index.js';
import { funcs, options } from './test-ws/index.js';

function handleSummary(data) {
return {
Expand All @@ -35,7 +35,6 @@ function handleSummary(data) {
function run(testParameters) {
const scenario = exec.scenario;
funcs[scenario.name](testParameters, scenario.iterationInTest, exec.vu.idInInstance - 1, exec.vu.iterationInScenario);
scenarioDurationGauge.add(Date.now() - scenario.startTime, { scenario: scenario.name });
}

export { handleSummary, options, run };
Expand Down

0 comments on commit dfcb7cf

Please sign in to comment.