From abc8f6831bb1150d8e31b6806ba9a8745944246c Mon Sep 17 00:00:00 2001 From: Abhishek Bhatia <117628830+abhishekbhatia1710@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:25:01 +0530 Subject: [PATCH] [Entity Analytics] Adding changes in the Integration test to wait for everything to be deleted before checking final status (#194447) ## Summary Includes a wait to check for deleted resources before verifying the risk engine status ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --- .../risk_engine_cleanup_api.ts | 8 +++++ .../entity_analytics/utils/risk_engine.ts | 34 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/risk_engine/trial_license_complete_tier/risk_engine_cleanup_api.ts b/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/risk_engine/trial_license_complete_tier/risk_engine_cleanup_api.ts index ee6c5a3414fcc..968b234509d34 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/risk_engine/trial_license_complete_tier/risk_engine_cleanup_api.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/risk_engine/trial_license_complete_tier/risk_engine_cleanup_api.ts @@ -13,6 +13,9 @@ import { riskEngineRouteHelpersFactory, waitForRiskScoresToBePresent, createAndSyncRuleAndAlertsFactory, + waitForRiskEngineTaskToBeGone, + waitForSavedObjectToBeGone, + waitForRiskScoresToBeGone, } from '../../utils'; import { dataGeneratorFactory } from '../../../detections_response/utils'; @@ -22,6 +25,7 @@ export default ({ getService }: FtrProviderContext) => { const es = getService('es'); const log = getService('log'); const esArchiver = getService('esArchiver'); + const kibanaServer = getService('kibanaServer'); describe('@ess @ serverless @serverless QA risk_engine_cleanup_api', () => { const createAndSyncRuleAndAlerts = createAndSyncRuleAndAlertsFactory({ supertest, log }); @@ -59,6 +63,10 @@ export default ({ getService }: FtrProviderContext) => { cleanup_successful: true, }); + await waitForRiskEngineTaskToBeGone({ es, log }); + await waitForSavedObjectToBeGone({ log, kibanaServer }); + await waitForRiskScoresToBeGone({ es, log }); + const status3 = await riskEngineRoutes.getStatus(); expect(status3.body.risk_engine_status).to.be('NOT_INSTALLED'); expect(status3.body.legacy_risk_engine_status).to.be('NOT_INSTALLED'); diff --git a/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/risk_engine.ts b/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/risk_engine.ts index 23a6c11b0b5cc..0a88e9fbe2518 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/risk_engine.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/entity_analytics/utils/risk_engine.ts @@ -331,6 +331,40 @@ export const waitForRiskEngineTaskToBeGone = async ({ ); }; +export const waitForSavedObjectToBeGone = async ({ + log, + kibanaServer, +}: { + log: ToolingLog; + kibanaServer: KbnClient; +}): Promise => { + await waitFor( + async () => { + const savedObject = await getRiskEngineConfigSO({ kibanaServer }); + return savedObject == null; + }, + 'waitForSavedObjectToBeGone', + log + ); +}; + +export const waitForRiskScoresToBeGone = async ({ + es, + log, +}: { + es: Client; + log: ToolingLog; +}): Promise => { + await waitFor( + async () => { + const riskScoreIndicesEmpty = await areRiskScoreIndicesEmpty({ es, log }); + return riskScoreIndicesEmpty; + }, + 'waitForRiskScoreIndicesToBeEmpty', + log + ); +}; + export const getRiskEngineConfigSO = async ({ kibanaServer }: { kibanaServer: KbnClient }) => { const soResponse = await kibanaServer.savedObjects.find({ type: riskEngineConfigurationTypeName,