Skip to content

Commit

Permalink
Fixed indice assertion to loop through expected keys (#64684)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
John Dorlus and elasticmachine authored May 6, 2020
1 parent 38c26ff commit f891a01
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand All @@ -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
});
});
Expand Down

0 comments on commit f891a01

Please sign in to comment.