Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Start/stop performance metrics collection for each test case without glue code #236

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions cypress/support/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ module.exports = {
SCENARIO_NAME: 'scenarioName',
FIREBOLT_INTERACTION: 'FireboltInteraction',
PENDING_FEATURES: 'pendingFeatures',
PERFORMANCE_VALIDATION: 'performanceValidation',
};
function getSanityReportPath() {
// Check if Cypress is defined, for cypress test context
Expand Down
27 changes: 23 additions & 4 deletions cypress/support/cypress-commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,6 @@ Cypress.Commands.add('parsedMockData', (beforeOperation) => {
* cy.startOrStopPerformanceService('stopped')
*/
Cypress.Commands.add('startOrStopPerformanceService', (action) => {
if (action == CONSTANTS.INITIATED) {
const epochTime = Number.parseInt(Date.now() / 1000);
Cypress.env(CONSTANTS.THRESHOLD_MONITOR_START_TIME, epochTime);
}
const requestMap = {
method: CONSTANTS.REQUEST_OVERRIDE_CALLS.SETPERFORMANCETESTHANDLER,
params: {
Expand Down Expand Up @@ -1270,6 +1266,9 @@ Cypress.Commands.add('methodOrEventResponseValidation', (validationType, request
case CONSTANTS.SCREENSHOT_VALIDATION:
cy.screenshotValidation(object);
break;
case CONSTANTS.PERFORMANCE_VALIDATION:
cy.performanceValidation(object);
break;
default:
assert(false, 'Unsupported validation type');
break;
Expand Down Expand Up @@ -1549,3 +1548,23 @@ Cypress.Commands.add('startOrStopInteractionsService', (action) => {
Cypress.Commands.add('envConfigSetup', () => {
fireLog.info('No additional config module environment setup');
});

neeradanelxsi marked this conversation as resolved.
Show resolved Hide resolved
Cypress.Commands.add('initiatePerformanceMetrics', () => {
const scenarioName = Cypress.env(CONSTANTS.SCENARIO_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we only need the scenarioName when we enter the if condition on line 1564. Do we need it to be defined outside of that block?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defined scenarioName inside if block.


if (UTILS.getEnvVariable(CONSTANTS.PERFORMANCE_METRICS) === true) {
const requestMap = {
method: CONSTANTS.REQUEST_OVERRIDE_CALLS.CREATE_MARKER,
params: scenarioName,
};
fireLog.info(`Firebolt Call to 1st party App: ${JSON.stringify(requestMap)} `);
cy.sendMessagetoPlatforms(requestMap).then((result) => {
fireLog.isTrue(result.success, 'Response for marker creation: ' + JSON.stringify(result));
});

neeradanelxsi marked this conversation as resolved.
Show resolved Hide resolved
const epochTime = Number.parseInt(Date.now() / 1000);
Cypress.env(CONSTANTS.THRESHOLD_MONITOR_START_TIME, epochTime);
} else {
cy.log(CONSTANTS.PERFORMANCE_METRICS_NOT_ACTIVE);
}
});
11 changes: 2 additions & 9 deletions cypress/support/cypress-support/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,6 @@ export default function (module) {
Cypress.env(CONSTANTS.MESSAGE_QUEUE, messageQueue);
UTILS.parseExceptionList();
cy.getModuleReqIdJson();
if (UTILS.getEnvVariable(CONSTANTS.PERFORMANCE_METRICS) == true) {
cy.startOrStopPerformanceService(CONSTANTS.INITIATED).then((response) => {
if (response) {
Cypress.env(CONSTANTS.IS_PERFORMANCE_METRICS_ENABLED, true);
}
});
} else {
cy.log(CONSTANTS.PERFORMANCE_METRICS_NOT_ACTIVE);
}
neeradanelxsi marked this conversation as resolved.
Show resolved Hide resolved

// Merge fireboltCalls
const v1FireboltCallsData = UTILS.getEnvVariable('fireboltCallsJson');
Expand Down Expand Up @@ -132,7 +123,9 @@ export default function (module) {
// beforeEach
beforeEach(() => {
UTILS.getEnvVariable(CONSTANTS.FB_INTERACTIONLOGS).clearLogs();

cy.getBeforeOperationObject();
cy.initiatePerformanceMetrics();
UTILS.destroyGlobalObjects([CONSTANTS.LIFECYCLE_APP_OBJECT_LIST]);
neeradanelxsi marked this conversation as resolved.
Show resolved Hide resolved
});

Expand Down
1 change: 1 addition & 0 deletions cypress/support/validations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ import './decodeValidation';
import './regExValidation';
import './schemaValidation';
import './undefinedValidation';
import './performanceValidation';
import './screenshotValidation';
49 changes: 49 additions & 0 deletions cypress/support/validations/performanceValidation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright 2024 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

const CONSTANTS = require('../constants/constants');
const UTILS = require('../cypress-support/src/utils');

Cypress.Commands.add('performanceValidation', (object) => {
if (UTILS.getEnvVariable('performanceMetrics')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to constant

const type = object.validations?.[0]?.type || 'all';
const process = object.validations?.[0]?.process || 'required';
const percentile = object.validations?.[0]?.percentile;
const threshold = object.validations?.[0]?.threshold;
const requestMap = {
method: CONSTANTS.REQUEST_OVERRIDE_CALLS.PERFORMANCE_THRESHOLD_VALIDATOR,
params: { type, process, percentile, threshold },
};

cy.sendMessagetoPlatforms(requestMap).then((result) => {
if (result.error) {
cy.log('Failed to fetch and validate the performance metrics').then(() => {
assert(false, result.error);
});
} else {
result.map((response) => {
cy.log(response.message).then(() => {
assert.equal(true, response?.success, response?.message);
});
});
}
});
} else {
fireLog.info('performanceMetrics are disabled.');
}
});
Loading