Skip to content

Commit 5a7bdf6

Browse files
[Saved Objects] Stabilize index-pattern relationships API test ordering (elastic#253451)
## Summary - Stabilizes the saved objects management relationships API test for index patterns by sorting relations before asserting equality. - Prevents flaky failures caused by non-deterministic relation ordering in API responses. - Closes elastic#244751 ## Test plan - [x] Run `node scripts/functional_test_runner --config src/platform/test/api_integration/config.ts --include-tag saved_objects_management` (or equivalent targeted API integration run) Made with [Cursor](https://cursor.com) Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent bacbe0f commit 5a7bdf6

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/platform/test/api_integration/apis/saved_objects_management/relationships.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ export default function ({ getService }: FtrProviderContext) {
7171
const typesQuery = types.map((t) => `savedObjectTypes=${t}`).join('&');
7272
return `${baseApiUrl}/${type}/${id}?${typesQuery}`;
7373
};
74+
const sortRelations = <TRelation extends { relationship: string; type: string; id: string }>(
75+
relations: TRelation[]
76+
) =>
77+
[...relations].sort((a, b) =>
78+
`${a.relationship}:${a.type}:${a.id}`.localeCompare(`${b.relationship}:${b.type}:${b.id}`)
79+
);
7480

7581
describe('searches', () => {
7682
it('should validate search response schema', async () => {
@@ -462,7 +468,7 @@ export default function ({ getService }: FtrProviderContext) {
462468
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
463469
.expect(200);
464470

465-
expect(resp.body.relations).to.eql([
471+
const expectedRelations = [
466472
{
467473
id: '960372e0-3224-11e8-a572-ffca06da1357',
468474
type: 'search',
@@ -509,7 +515,9 @@ export default function ({ getService }: FtrProviderContext) {
509515
},
510516
],
511517
},
512-
]);
518+
];
519+
520+
expect(sortRelations(resp.body.relations)).to.eql(sortRelations(expectedRelations));
513521
});
514522

515523
it('should filter based on savedObjectTypes', async () => {

0 commit comments

Comments
 (0)