From 347c138bc0424b1559533ba0507adba60234a62b Mon Sep 17 00:00:00 2001 From: Frank Hassanabad Date: Fri, 29 Oct 2021 16:08:13 -0600 Subject: [PATCH] Fixes flake seen on CI by sorting the results (#116846) ## Summary Sorting fix for flake test. Fixes: https://github.com/elastic/kibana/issues/116691 ### Checklist - [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 --- .../security_and_spaces/tests/runtime.ts | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/runtime.ts b/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/runtime.ts index 528a99715c05..293f3e758911 100644 --- a/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/runtime.ts +++ b/x-pack/test/detection_engine_api_integration/security_and_spaces/tests/runtime.ts @@ -53,7 +53,9 @@ export default ({ getService }: FtrProviderContext) => { await waitForRuleSuccessOrStatus(supertest, id); await waitForSignalsToBePresent(supertest, 4, [id]); const signalsOpen = await getSignalsById(supertest, id); - const hits = signalsOpen.hits.hits.map((signal) => (signal._source?.host as Runtime).name); + const hits = signalsOpen.hits.hits + .map((signal) => (signal._source?.host as Runtime).name) + .sort(); expect(hits).to.eql(['host name 1', 'host name 2', 'host name 3', 'host name 4']); }); @@ -63,9 +65,9 @@ export default ({ getService }: FtrProviderContext) => { await waitForRuleSuccessOrStatus(supertest, id); await waitForSignalsToBePresent(supertest, 4, [id]); const signalsOpen = await getSignalsById(supertest, id); - const hits = signalsOpen.hits.hits.map( - (signal) => (signal._source?.host as Runtime).hostname - ); + const hits = signalsOpen.hits.hits + .map((signal) => (signal._source?.host as Runtime).hostname) + .sort(); expect(hits).to.eql(['host name 1', 'host name 2', 'host name 3', 'host name 4']); }); }); @@ -97,7 +99,16 @@ export default ({ getService }: FtrProviderContext) => { await waitForRuleSuccessOrStatus(supertest, id); await waitForSignalsToBePresent(supertest, 4, [id]); const signalsOpen = await getSignalsById(supertest, id); - const hits = signalsOpen.hits.hits.map((signal) => signal._source?.host); + const hits = signalsOpen.hits.hits + .map((signal) => signal._source?.host as Array<{ name: string }>) + .map((host) => { + // sort the inner array elements first + return host.sort((a, b) => a.name.localeCompare(b.name)); + }) + .sort((aArray, bArray) => { + // since these are all unique, using just the first element should give us stability + return aArray[0].name.localeCompare(bArray[0].name); + }); expect(hits).to.eql([ [ {