From c95fbe5d598ae421b229f10402951424ec3cd4f2 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 21 Apr 2021 23:16:30 -0400 Subject: [PATCH] [Security Solution][Detections] Fix flaky threshold API tests (#97768) (#97898) * Explicitly refreshes signals index for threshold api tests to prevent flakiness * Unskip test suite Co-authored-by: Marshall Main <55718608+marshallmain@users.noreply.github.com> --- .../tests/generating_signals.ts | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/generating_signals.ts b/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/generating_signals.ts index 7d69e006666cd..4ae949d0cba86 100644 --- a/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/generating_signals.ts +++ b/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/generating_signals.ts @@ -20,6 +20,7 @@ import { createSignalsIndex, deleteAllAlerts, deleteSignalsIndex, + getOpenSignals, getRuleForSignalTesting, getSignalsByIds, getSignalsByRuleIds, @@ -39,9 +40,9 @@ export const ID = 'BhbXBmkBR346wHgn4PeZ'; export default ({ getService }: FtrProviderContext) => { const supertest = getService('supertest'); const esArchiver = getService('esArchiver'); + const es = getService('es'); - // FLAKY: https://github.com/elastic/kibana/issues/97584 - describe.skip('Generating signals from source indexes', () => { + describe('Generating signals from source indexes', () => { beforeEach(async () => { await createSignalsIndex(supertest); }); @@ -728,9 +729,8 @@ export default ({ getService }: FtrProviderContext) => { ], }, }; - const { id } = await createRule(supertest, rule); - await waitForRuleSuccessOrStatus(supertest, id); - const signalsOpen = await getSignalsByRuleIds(supertest, [ruleId]); + const createdRule = await createRule(supertest, rule); + const signalsOpen = await getOpenSignals(supertest, es, createdRule); expect(signalsOpen.hits.hits.length).eql(0); }); @@ -753,9 +753,8 @@ export default ({ getService }: FtrProviderContext) => { ], }, }; - const { id } = await createRule(supertest, rule); - await waitForRuleSuccessOrStatus(supertest, id); - const signalsOpen = await getSignalsByRuleIds(supertest, [ruleId]); + const createdRule = await createRule(supertest, rule); + const signalsOpen = await getOpenSignals(supertest, es, createdRule); expect(signalsOpen.hits.hits.length).eql(0); }); @@ -778,9 +777,8 @@ export default ({ getService }: FtrProviderContext) => { ], }, }; - const { id } = await createRule(supertest, rule); - await waitForRuleSuccessOrStatus(supertest, id); - const signalsOpen = await getSignalsByRuleIds(supertest, [ruleId]); + const createdRule = await createRule(supertest, rule); + const signalsOpen = await getOpenSignals(supertest, es, createdRule); expect(signalsOpen.hits.hits.length).eql(1); const signal = signalsOpen.hits.hits[0]; expect(signal._source.signal.threshold_result).eql({ @@ -814,9 +812,8 @@ export default ({ getService }: FtrProviderContext) => { value: 22, }, }; - const { id } = await createRule(supertest, rule); - await waitForRuleSuccessOrStatus(supertest, id); - const signalsOpen = await getSignalsByRuleIds(supertest, [ruleId]); + const createdRule = await createRule(supertest, rule); + const signalsOpen = await getOpenSignals(supertest, es, createdRule); expect(signalsOpen.hits.hits.length).eql(0); }); @@ -833,9 +830,8 @@ export default ({ getService }: FtrProviderContext) => { value: 21, }, }; - const { id } = await createRule(supertest, rule); - await waitForRuleSuccessOrStatus(supertest, id); - const signalsOpen = await getSignalsByRuleIds(supertest, [ruleId]); + const createdRule = await createRule(supertest, rule); + const signalsOpen = await getOpenSignals(supertest, es, createdRule); expect(signalsOpen.hits.hits.length).eql(1); const signal = signalsOpen.hits.hits[0]; expect(signal._source.signal.threshold_result).eql({