From 78b21cd9f98f65d93bfba4b3a2d0e5b33f481c26 Mon Sep 17 00:00:00 2001 From: Tre Date: Wed, 18 Sep 2024 16:31:11 +0100 Subject: [PATCH] [Unskip] x-pack/.../summary_actions.ts (#193120) ## Summary Use retryForTime instead. Test against local (fake mki) and mki; both were security projects. Tested against `x-pack/test_serverless/api_integration/test_suites/security/common_configs/config.group1.ts` Resolves: https://github.com/elastic/kibana/issues/193061 --------- Co-authored-by: Elastic Machine --- .../common/alerting/summary_actions.ts | 10 ++--- .../shared/services/alerting_api.ts | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/x-pack/test_serverless/api_integration/test_suites/common/alerting/summary_actions.ts b/x-pack/test_serverless/api_integration/test_suites/common/alerting/summary_actions.ts index ec63653bef7c7..d5f04e692acfe 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/alerting/summary_actions.ts +++ b/x-pack/test_serverless/api_integration/test_suites/common/alerting/summary_actions.ts @@ -39,8 +39,7 @@ export default function ({ getService }: FtrProviderContext) { const alertingApi = getService('alertingApi'); let roleAdmin: RoleCredentials; - // Failing: See https://github.com/elastic/kibana/issues/193061 - describe.skip('Summary actions', function () { + describe('Summary actions', function () { const RULE_TYPE_ID = '.es-query'; const ALERT_ACTION_INDEX = 'alert-action-es-query'; const ALERT_INDEX = '.alerts-stack.alerts-default'; @@ -491,16 +490,13 @@ export default function ({ getService }: FtrProviderContext) { }); ruleId = createdRule.id; - const resp = await alertingApi.helpers.waitForDocumentInIndex({ + const resp = await alertingApi.helpers.waitForDocumentInIndexForTime({ esClient, indexName: ALERT_ACTION_INDEX, ruleId, num: 2, sort: 'asc', - retryOptions: { - retryCount: 20, - retryDelay: 10_000, - }, + timeout: 180_000, }); const resp2 = await alertingApi.helpers.waitForAlertInIndex({ diff --git a/x-pack/test_serverless/shared/services/alerting_api.ts b/x-pack/test_serverless/shared/services/alerting_api.ts index afed22fbe2c9a..86fcad5060cc6 100644 --- a/x-pack/test_serverless/shared/services/alerting_api.ts +++ b/x-pack/test_serverless/shared/services/alerting_api.ts @@ -102,6 +102,46 @@ export function AlertingApiProvider({ getService }: FtrProviderContext) { ); }, + async waitForDocumentInIndexForTime({ + esClient, + indexName, + ruleId, + num = 1, + sort = 'desc', + timeout = 1000, + }: { + esClient: Client; + indexName: string; + ruleId: string; + num?: number; + sort?: 'asc' | 'desc'; + timeout?: number; + }): Promise { + return await retry.tryForTime(timeout, async () => { + const response = await esClient.search({ + index: indexName, + sort: `date:${sort}`, + body: { + query: { + bool: { + must: [ + { + term: { + 'ruleId.keyword': ruleId, + }, + }, + ], + }, + }, + }, + }); + if (response.hits.hits.length < num) { + throw new Error(`Only found ${response.hits.hits.length} / ${num} documents`); + } + return response; + }); + }, + async waitForDocumentInIndex({ esClient, indexName,