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

[Cypress][Flake][Detection Engine] Fix flakey add/edit exception test #171697

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
} from '../../../../tasks/alerts_detection_rules';
import { fetchRuleAlerts } from '../../../../tasks/api_calls/alerts';
import {
enablesRule,
clickEnableDisableSwitch,
visitRuleDetailsPage,
waitForPageToBeLoaded,
} from '../../../../tasks/rule_details';
Expand Down Expand Up @@ -213,7 +213,7 @@ describe('Related integrations', { tags: ['@ess', '@serverless', '@brokenInServe
deleteDataStream(DATA_STREAM_NAME);
createDocument(DATA_STREAM_NAME, generateEvent());

enablesRule();
clickEnableDisableSwitch();
waitForAlertsToPopulate();

fetchRuleAlerts({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { login } from '../../../tasks/login';
import {
openExceptionFlyoutFromEmptyViewerPrompt,
visitRuleDetailsPage,
enablesRule,
clickEnableDisableSwitch,
waitForTheRuleToBeExecuted,
goToAlertsTab,
} from '../../../tasks/rule_details';
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('Exceptions match_any', { tags: ['@ess', '@serverless'] }, () => {
cy.get(CONFIRM_BTN).should('be.enabled');
submitNewExceptionItem();

enablesRule();
clickEnableDisableSwitch();

goToAlertsTab();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { login } from '../../../tasks/login';
import {
addFirstExceptionFromRuleDetails,
clickEnableDisableSwitch,
goToAlertsTab,
goToExceptionsTab,
openEditException,
Expand All @@ -43,7 +44,7 @@ import { waitForAlertsToPopulate } from '../../../tasks/create_new_rule';
// TODO: https://github.com/elastic/kibana/issues/161539
describe(
'Add exception using data views from rule details',
{ tags: ['@ess', '@serverless', '@brokenInServerless'] },
{ tags: ['@ess', '@serverless'] },
() => {
const NUMBER_OF_AUDITBEAT_EXCEPTIONS_ALERTS = '3 alerts';
const ITEM_NAME = 'Sample Exception List Item';
Expand All @@ -65,7 +66,6 @@ describe(
getNewRule({
query: 'agent.name:*',
data_view_id: 'exceptions-*',
interval: '10s',
rule_id: 'rule_testing',
})
).then((rule) => visitRuleDetailsPage(rule.body.id));
Expand All @@ -77,6 +77,9 @@ describe(
});

it('Creates an exception item and close all matching alerts', () => {
// Disables enabled rule
clickEnableDisableSwitch();

goToExceptionsTab();
// when no exceptions exist, empty component shows with action to add exception
cy.get(NO_EXCEPTIONS_EXIST_PROMPT).should('exist');
Expand Down Expand Up @@ -115,6 +118,8 @@ describe(

// load more docs
cy.task('esArchiverLoad', { archiveName: 'exceptions_2' });
// Enables disabled rule
clickEnableDisableSwitch();

// now that there are no more exceptions, the docs should match and populate alerts
goToAlertsTab();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function visitRuleDetailsPage(ruleId: string, options?: VisitRuleDetailsP
visit(ruleDetailsUrl(ruleId, options?.tab), { role: options?.role });
}

export const enablesRule = () => {
export const clickEnableDisableSwitch = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we need deterministic behavior here? If the rule was enabled for some reason this will disable it and the rest test logic won't be relevant. Should't some name like enableRuleViaSwitch() or just enableRule() should work better? On top of this the function should contain expectation that the switch in the right position.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The name definitely is confusing. There's nothing about the existing util logic that's checking the actual status (enabled or disabled). I went ahead and separated it into two utils that check the status appropriately.

// Rules get enabled via _bulk_action endpoint
cy.intercept('POST', '/api/detection_engine/rules/_bulk_action?dry_run=false').as('bulk_action');
cy.get(RULE_SWITCH).should('be.visible');
Expand Down