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 3 commits into
base: dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions cypress/support/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ module.exports = {
SET_EVENT_SUCCESS: 'Event value set successfully in platform',
SCENARIO_NAME: 'scenarioName',
FIREBOLT_INTERACTION: 'FireboltInteraction',
PERFORMANCE_VALIDATION: 'performanceValidation',
};
function getSanityReportPath() {
// Check if Cypress is defined, for cypress test context
Expand Down
3 changes: 3 additions & 0 deletions cypress/support/cypress-commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,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
52 changes: 41 additions & 11 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);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

why did you remove this code ? This function is to start/stop metrics collection and that should reside in before operation


// Merge fireboltCalls
const v1FireboltCallsData = UTILS.getEnvVariable('fireboltCallsJson');
Expand Down Expand Up @@ -132,8 +123,36 @@ export default function (module) {
// beforeEach
beforeEach(() => {
UTILS.getEnvVariable(CONSTANTS.FB_INTERACTIONLOGS).clearLogs();
cy.getBeforeOperationObject();
UTILS.destroyGlobalObjects([CONSTANTS.LIFECYCLE_APP_OBJECT_LIST]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are we adding a .then for lines 135 and 136.
You can create a new command which internally creates marker and save start time there. Then that command can be used in beforeeach right


cy.getBeforeOperationObject().then(() => {
const scenarioName = Cypress.env(CONSTANTS.SCENARIO_NAME);

UTILS.destroyGlobalObjects([CONSTANTS.LIFECYCLE_APP_OBJECT_LIST]);

if (UTILS.getEnvVariable(CONSTANTS.PERFORMANCE_METRICS) === true) {
if (scenarioName) {
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)
);
});

cy.startOrStopPerformanceService(CONSTANTS.INITIATED).then((response) => {
if (response) {
Cypress.env(CONSTANTS.IS_PERFORMANCE_METRICS_ENABLED, true);
}
});
}
} else {
cy.log(CONSTANTS.PERFORMANCE_METRICS_NOT_ACTIVE);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

line 146 is nto 150 is not correct

});
});

/**
Expand Down Expand Up @@ -242,6 +261,17 @@ export default function (module) {
})();
});

// after each
afterEach(() => {
if (UTILS.getEnvVariable(CONSTANTS.IS_PERFORMANCE_METRICS_ENABLED, false) == true) {
cy.startOrStopPerformanceService(CONSTANTS.STOPPED).then((response) => {
if (response) {
Cypress.env(CONSTANTS.IS_PERFORMANCE_METRICS_ENABLED, false);
}
});
}
});

/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not right, why are we stopping metrics collection in aftereach

* @module main
* @function sendMessagetoPlatforms
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';
46 changes: 46 additions & 0 deletions cypress/support/validations/performanceValidation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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')) {
const { type, process, percentile, threshold } = object.validations[0];
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