Skip to content

Commit

Permalink
[SecuritySolution] Fix flaky row_renderers cypress test (#158557)
Browse files Browse the repository at this point in the history
## Summary

#153767

![Row renderers -- Selected renderer can be disabled and enabled
(failed) (attempt
3)](https://user-images.githubusercontent.com/17427073/227953233-76ebfafe-17b6-4d83-9b6a-ba647f6709ae.png)


The cause of the flakiness might originated from intercepting two
requests with the same name, therefore when running under the slow
internet, some weird behaviour might happen. I'm guessing that the
failure was caused as the second request had already sent while we were
expecting the first request.
Therefor I'm setting the two requests with different names, hopefully
this can reduce the flakiness.
  • Loading branch information
angorayc authored Jun 19, 2023
1 parent 257c5f2 commit 8e6bf63
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ import {
TIMELINE_ROW_RENDERERS_SURICATA_SIGNATURE_TOOLTIP,
TIMELINE_ROW_RENDERERS_SURICATA_LINK_TOOLTIP,
} from '../../../screens/timeline';
import { cleanKibana, deleteTimelines } from '../../../tasks/common';
import {
cleanKibana,
deleteTimelines,
waitForPageToBeLoaded,
waitForWelcomePanelToBeLoaded,
} from '../../../tasks/common';
import { waitForAllHostsToBeLoaded } from '../../../tasks/hosts/all_hosts';

import { login, visit } from '../../../tasks/login';
import { openTimelineUsingToggle } from '../../../tasks/security_main';
Expand All @@ -31,7 +37,13 @@ describe('Row renderers', () => {
beforeEach(() => {
deleteTimelines();
login();
visit(HOSTS_URL);
visit(HOSTS_URL, {
onLoad: () => {
waitForWelcomePanelToBeLoaded();
waitForPageToBeLoaded();
waitForAllHostsToBeLoaded();
},
});
openTimelineUsingToggle();
populateTimeline();
cy.get(TIMELINE_SHOW_ROW_RENDERERS_GEAR).should('exist');
Expand All @@ -48,17 +60,27 @@ describe('Row renderers', () => {
cy.get(TIMELINE_ROW_RENDERERS_SEARCHBOX).type('flow');

// Intercepts should be before click handlers that activate them rather than afterwards or you have race conditions
cy.intercept('PATCH', '/api/timeline').as('updateTimeline');
cy.intercept('PATCH', '/api/timeline', (req) => {
if (req.body.timeline.excludedRowRendererIds.includes('netflow')) {
req.alias = 'excludedNetflow';
} else {
req.alias = 'includedNetflow';
}
});
cy.get(TIMELINE_ROW_RENDERERS_MODAL_ITEMS_CHECKBOX).first().uncheck();

cy.wait('@updateTimeline').then((interception) => {
expect(interception.request.body.timeline.excludedRowRendererIds).to.contain('netflow');
cy.wait('@excludedNetflow').then((interception) => {
expect(
interception?.response?.body.data.persistTimeline.timeline.excludedRowRendererIds
).to.contain('netflow');
});

cy.get(TIMELINE_ROW_RENDERERS_MODAL_ITEMS_CHECKBOX).first().check();

cy.wait('@updateTimeline').then((interception) => {
expect(interception.request.body.timeline.excludedRowRendererIds).not.to.contain('netflow');
cy.wait('@includedNetflow').then((interception) => {
expect(
interception?.response?.body.data.persistTimeline.timeline.excludedRowRendererIds
).not.to.contain('netflow');
});
});

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/security_solution/cypress/tasks/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* 2.0.
*/

import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { DATA_VIEW_PATH, INITIAL_REST_VERSION } from '@kbn/data-views-plugin/server/constants';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import {
KIBANA_LOADING_ICON,
LOADING_INDICATOR,
LOADING_INDICATOR_HIDDEN,
KIBANA_LOADING_ICON,
} from '../screens/security_header';

const primaryButton = 0;
Expand Down

0 comments on commit 8e6bf63

Please sign in to comment.