From 43b31dced7cdb3e4d111110c7384d9ae7cdc3ba3 Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Thu, 30 Apr 2020 15:38:33 +0100 Subject: [PATCH] ensure correct ordered creation in both tests --- .../event_log/public_api_integration.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/x-pack/test/plugin_api_integration/test_suites/event_log/public_api_integration.ts b/x-pack/test/plugin_api_integration/test_suites/event_log/public_api_integration.ts index b9c5dfbb88b3ae..869ce1def7cd0f 100644 --- a/x-pack/test/plugin_api_integration/test_suites/event_log/public_api_integration.ts +++ b/x-pack/test/plugin_api_integration/test_suites/event_log/public_api_integration.ts @@ -80,12 +80,7 @@ export default function({ getService }: FtrProviderContext) { it('should support sorting by event end', async () => { const id = uuid.v4(); - const expectedEvents: IEvent[] = []; - for (let index = 0; index < 6; index++) { - const event = fakeEvent(id); - await logTestEvent(id, event); - expectedEvents.push(event); - } + const expectedEvents = await logFakeEvents(id, 6); await retry.try(async () => { const { @@ -109,8 +104,7 @@ export default function({ getService }: FtrProviderContext) { const start = new Date().toISOString(); // write the documents that we should be found in the date range searches - const expectedEvents = times(6, () => fakeEvent(id)); - await Promise.all(expectedEvents.map(event => logTestEvent(id, event))); + const expectedEvents = await logFakeEvents(id, 6); // get the end time for the date range search const end = new Date().toISOString(); @@ -215,4 +209,14 @@ export default function({ getService }: FtrProviderContext) { overrides ); } + + async function logFakeEvents(savedObjectId: string, eventsToLog: number): Promise { + const expectedEvents: IEvent[] = []; + for (let index = 0; index < eventsToLog; index++) { + const event = fakeEvent(savedObjectId); + await logTestEvent(savedObjectId, event); + expectedEvents.push(event); + } + return expectedEvents; + } }