From f891a0150a990f4f830f6bf70a7865dfe4a36c00 Mon Sep 17 00:00:00 2001 From: John Dorlus Date: Wed, 6 May 2020 15:45:32 -0400 Subject: [PATCH] Fixed indice assertion to loop through expected keys (#64684) * Changed assertion to loop through expected keys and confirm that they are contained within the array. Also made sure that the two arrays have the same length. Those two assertions should make sure that the contents are the same no matter the order of the keys. * Changed assertion to loop through expected keys and confirm that they are contained within the array. Also made sure that the two arrays have the same length. Those two assertions should make sure that the contents are the same no matter the order of the keys. * Fixed typo in function. * Changed assertion per conversation. * Updated assertion on second test. * Fixed assertion for equality that's not strict. * Added comment to code to explain why the arrays were sorted. Co-authored-by: Elastic Machine --- .../apis/management/index_management/indices.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/x-pack/test/api_integration/apis/management/index_management/indices.js b/x-pack/test/api_integration/apis/management/index_management/indices.js index 9442beda3501..041219280870 100644 --- a/x-pack/test/api_integration/apis/management/index_management/indices.js +++ b/x-pack/test/api_integration/apis/management/index_management/indices.js @@ -199,7 +199,11 @@ export default function({ getService }) { 'ilm', // data enricher 'isRollupIndex', // data enricher ]; - expect(Object.keys(body[0])).to.eql(expectedKeys); + // We need to sort the keys before comparing then, because race conditions + // can cause enrichers to register in non-deterministic order. + const sortedExpectedKeys = expectedKeys.sort(); + const sortedReceivedKeys = Object.keys(body[0]).sort(); + expect(sortedReceivedKeys).to.eql(sortedExpectedKeys); }); }); @@ -225,7 +229,11 @@ export default function({ getService }) { 'ilm', // data enricher 'isRollupIndex', // data enricher ]; - expect(Object.keys(body[0])).to.eql(expectedKeys); + // We need to sort the keys before comparing then, because race conditions + // can cause enrichers to register in non-deterministic order. + const sortedExpectedKeys = expectedKeys.sort(); + const sortedReceivedKeys = Object.keys(body[0]).sort(); + expect(sortedReceivedKeys).to.eql(sortedExpectedKeys); expect(body.length > 1).to.be(true); // to contrast it with the next test }); });