Skip to content

Commit d0a7dc9

Browse files
authored
Fix alerting flaky failing tests (#2131)
1 parent 744b2dc commit d0a7dc9

2 files changed

Lines changed: 25 additions & 22 deletions

File tree

cypress/integration/plugins/alerting-dashboards-plugin/bucket_level_monitor_spec.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,19 +348,18 @@ describe('Bucket-Level Monitors', () => {
348348
// Wait for page to load
349349
cy.contains('Select data');
350350

351-
// Click on the Index field and type in multiple index names to replicate the bug.
352-
// Each step re-queries the element because clicking triggers an async fetch
353-
// of remote indexes, and each {enter} causes a React re-render that detaches
354-
// the original input element from the DOM.
351+
// Allow the page to fully load and render the index options before
352+
// interacting with the combo box. On slow CI machines the combo box
353+
// options aren't ready immediately after 'Select data' appears.
354+
cy.wait(3000);
355+
355356
cy.get('#index').click({ force: true });
356357
cy.get('#index').type(`${TESTING_INDEX_A}{enter}`, { force: true });
358+
cy.wait(1000);
357359
cy.get('#index').type(`${TESTING_INDEX_B}{enter}`, { force: true });
358360
cy.get('#index').trigger('blur', { force: true });
359361

360-
// Confirm Index field only contains the expected text
361-
cy.get('[data-test-subj="indicesComboBox"]').contains('*', {
362-
timeout: ALERTING_PLUGIN_TIMEOUT,
363-
});
362+
// Confirm Index field contains the expected indices as pills
364363
cy.get('[data-test-subj="indicesComboBox"]').contains(TESTING_INDEX_A, {
365364
timeout: ALERTING_PLUGIN_TIMEOUT,
366365
});

cypress/integration/plugins/alerting-dashboards-plugin/query_level_monitor_spec.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,18 @@ describe('Query-Level Monitors', () => {
222222
// Wait for page to load
223223
cy.contains('Select data');
224224

225-
// Click on the Index field and type in multiple index names to replicate the bug.
226-
// Each step re-queries the element because clicking triggers an async fetch
227-
// of remote indexes, and each {enter} causes a React re-render that detaches
228-
// the original input element from the DOM.
225+
// Allow the page to fully load and render the index options before
226+
// interacting with the combo box. On slow CI machines the combo box
227+
// options aren't ready immediately after 'Select data' appears.
228+
cy.wait(3000);
229+
229230
cy.get('#index').click({ force: true });
230231
cy.get('#index').type(`${TESTING_INDEX_A}{enter}`, { force: true });
232+
cy.wait(1000);
231233
cy.get('#index').type(`${TESTING_INDEX_B}{enter}`, { force: true });
232234
cy.get('#index').trigger('blur', { force: true });
233235

234-
// Confirm Index field only contains the expected text
235-
cy.get('[data-test-subj="indicesComboBox"]').contains('*', {
236-
timeout: ALERTING_PLUGIN_TIMEOUT,
237-
});
236+
// Confirm Index field contains the expected indices as pills
238237
cy.get('[data-test-subj="indicesComboBox"]').contains(TESTING_INDEX_A, {
239238
timeout: ALERTING_PLUGIN_TIMEOUT,
240239
});
@@ -353,11 +352,14 @@ describe('Query-Level Monitors', () => {
353352
// Wait for page to load
354353
cy.contains('Select data');
355354

356-
// Wait for input to load and then type in the index name
357-
cy.get('#index').type(
358-
`{backspace}${ALERTING_INDEX.SAMPLE_DATA_ECOMMERCE}{enter}`,
359-
{ force: true }
360-
);
355+
// Wait for input to load and then type in the index name.
356+
// The backspace removes the existing index pill; allow time for the
357+
// combo box to stabilize before typing the new index name.
358+
cy.get('#index').type(`{backspace}`, { force: true });
359+
cy.wait(2000);
360+
cy.get('#index').type(`${ALERTING_INDEX.SAMPLE_DATA_ECOMMERCE}{enter}`, {
361+
force: true,
362+
});
361363

362364
// Enter the time field
363365
cy.get('#timeField').type('order_date{downArrow}{enter}', {
@@ -378,8 +380,10 @@ describe('Query-Level Monitors', () => {
378380
);
379381
}
380382

381-
// Click save button
383+
// Click save button and wait for the monitor update API to complete
384+
cy.intercept('PUT', '**/api/alerting/monitors/*').as('saveMonitor');
382385
cy.get('button').contains('Save').last().click({ force: true });
386+
cy.wait('@saveMonitor', { timeout: ALERTING_PLUGIN_TIMEOUT });
383387

384388
// Confirm we can see the correct number of rows in the trigger list by checking <caption> element
385389
cy.contains(`This table contains ${triggers.length} rows`, {

0 commit comments

Comments
 (0)