From ff543226e85c7a6f156613627fd59c35c0bc02c4 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 17 Jun 2025 05:27:19 +0200 Subject: [PATCH] [9.0] [UI Counters] fix flaky test retry logic (#224151) (#224167) # Backport This will backport the following commits from `main` to `9.0`: - [[UI Counters] fix flaky test retry logic (#224151)](https://github.com/elastic/kibana/pull/224151) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) Co-authored-by: Ahmad Bamieh --- .../apis/ui_counters/ui_counters.ts | 78 +++++++++++-------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/test/api_integration/apis/ui_counters/ui_counters.ts b/test/api_integration/apis/ui_counters/ui_counters.ts index 64f0adb17a4c..1f8823d94eeb 100644 --- a/test/api_integration/apis/ui_counters/ui_counters.ts +++ b/test/api_integration/apis/ui_counters/ui_counters.ts @@ -15,6 +15,8 @@ import { FtrProviderContext } from '../../ftr_provider_context'; const APP_NAME = 'myApp'; +const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); + export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const esArchiver = getService('esArchiver'); @@ -91,15 +93,21 @@ export default function ({ getService }: FtrProviderContext) { const { report } = reportManager.assignReports([counterEvent]); await sendReport(report); - await retry.waitForWithTimeout('reported events to be stored into ES', 8000, async () => { - const savedObjects = await fetchUsageCountersObjects(); + // Wait for the report to be query-able in ES since sending report uses (refresh = false) + await delay(3000); + await retry.tryWithRetries( + 'reported events to be stored into ES', + async () => { + const savedObjects = await fetchUsageCountersObjects(); - const countTypeEvents = getCounter(savedObjects, eventName, METRIC_TYPE.COUNT); + const countTypeEvents = getCounter(savedObjects, eventName, METRIC_TYPE.COUNT); - expect(countTypeEvents.length).to.eql(1); - expect(countTypeEvents[0].attributes.count).to.eql(1); - return true; - }); + expect(countTypeEvents.length).to.eql(1); + expect(countTypeEvents[0].attributes.count).to.eql(1); + return true; + }, + { retryCount: 6, retryDelay: 1500 } + ); }); it('supports multiple events', async () => { @@ -115,33 +123,39 @@ export default function ({ getService }: FtrProviderContext) { ]); await sendReport(report); - await retry.waitForWithTimeout('reported events to be stored into ES', 8000, async () => { - const savedObjects = await fetchUsageCountersObjects(); - const firstEventWithCountTypeEvents = getCounter( - savedObjects, - firstUniqueEventName, - METRIC_TYPE.COUNT - ); - expect(firstEventWithCountTypeEvents.length).to.eql(1); - expect(firstEventWithCountTypeEvents[0].attributes.count).to.eql(1); + // Wait for the report to be query-able in ES since sending report uses (refresh = false) + await delay(3000); + await retry.tryWithRetries( + 'reported events to be stored into ES', + async () => { + const savedObjects = await fetchUsageCountersObjects(); + const firstEventWithCountTypeEvents = getCounter( + savedObjects, + firstUniqueEventName, + METRIC_TYPE.COUNT + ); + expect(firstEventWithCountTypeEvents.length).to.eql(1); + expect(firstEventWithCountTypeEvents[0].attributes.count).to.eql(1); - const firstEventWithClickTypeEvents = getCounter( - savedObjects, - firstUniqueEventName, - METRIC_TYPE.CLICK - ); - expect(firstEventWithClickTypeEvents.length).to.eql(1); - expect(firstEventWithClickTypeEvents[0].attributes.count).to.eql(2); + const firstEventWithClickTypeEvents = getCounter( + savedObjects, + firstUniqueEventName, + METRIC_TYPE.CLICK + ); + expect(firstEventWithClickTypeEvents.length).to.eql(1); + expect(firstEventWithClickTypeEvents[0].attributes.count).to.eql(2); - const secondEventWithCountTypeEvents = getCounter( - savedObjects, - secondUniqueEventName, - METRIC_TYPE.COUNT - ); - expect(secondEventWithCountTypeEvents.length).to.eql(1); - expect(secondEventWithCountTypeEvents[0].attributes.count).to.eql(1); - return true; - }); + const secondEventWithCountTypeEvents = getCounter( + savedObjects, + secondUniqueEventName, + METRIC_TYPE.COUNT + ); + expect(secondEventWithCountTypeEvents.length).to.eql(1); + expect(secondEventWithCountTypeEvents[0].attributes.count).to.eql(1); + return true; + }, + { retryCount: 6, retryDelay: 1500 } + ); }); }); }