From 0af086c8b9ae1f5f5913561a5d57599ebd4a1451 Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Wed, 29 Apr 2020 15:44:33 +0100 Subject: [PATCH 1/4] ensur eevent log test is less flaky --- .../test_suites/event_log/public_api_integration.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 e5b840b335846..16d79cee08ea9 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 @@ -83,7 +83,10 @@ export default function({ getService }: FtrProviderContext) { const [firstExpectedEvent, ...expectedEvents] = times(6, () => fakeEvent(id)); // run one first to create the SO and avoid clashes await logTestEvent(id, firstExpectedEvent); - await Promise.all(expectedEvents.map(event => logTestEvent(id, event))); + // stagger the API calls to ensure the creation order is as expected + for (let index = 0; index < expectedEvents.length; index++) { + await logTestEvent(id, expectedEvents[index]); + } await retry.try(async () => { const { From 471fe080484f937a6c52b653c37ff69d44a0a85c Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Thu, 30 Apr 2020 11:18:16 +0100 Subject: [PATCH 2/4] ensure end field is actually set --- .../plugins/event_log/server/init_routes.ts | 3 +++ .../event_log/public_api_integration.ts | 22 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/x-pack/test/plugin_api_integration/plugins/event_log/server/init_routes.ts b/x-pack/test/plugin_api_integration/plugins/event_log/server/init_routes.ts index c5f3e65581df9..bb49d17064541 100644 --- a/x-pack/test/plugin_api_integration/plugins/event_log/server/init_routes.ts +++ b/x-pack/test/plugin_api_integration/plugins/event_log/server/init_routes.ts @@ -42,6 +42,9 @@ export const logEventRoute = (router: IRouter, eventLogger: IEventLogger, logger await context.core.savedObjects.client.create('event_log_test', {}, { id }); logger.info(`created saved object`); } + // mark now as start and end + eventLogger.startTiming(event); + eventLogger.stopTiming(event); eventLogger.logEvent(event); logger.info(`logged`); return res.ok({}); 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 16d79cee08ea9..b9c5dfbb88b3a 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,11 @@ export default function({ getService }: FtrProviderContext) { it('should support sorting by event end', async () => { const id = uuid.v4(); - const [firstExpectedEvent, ...expectedEvents] = times(6, () => fakeEvent(id)); - // run one first to create the SO and avoid clashes - await logTestEvent(id, firstExpectedEvent); - // stagger the API calls to ensure the creation order is as expected - for (let index = 0; index < expectedEvents.length; index++) { - await logTestEvent(id, expectedEvents[index]); + const expectedEvents: IEvent[] = []; + for (let index = 0; index < 6; index++) { + const event = fakeEvent(id); + await logTestEvent(id, event); + expectedEvents.push(event); } await retry.try(async () => { @@ -93,11 +92,8 @@ export default function({ getService }: FtrProviderContext) { body: { data: foundEvents }, } = await findEvents(id, { sort_field: 'event.end', sort_order: 'desc' }); - expect(foundEvents.length).to.be(6); - assertEventsFromApiMatchCreatedEvents( - foundEvents, - [firstExpectedEvent, ...expectedEvents].reverse() - ); + expect(foundEvents.length).to.be(expectedEvents.length); + assertEventsFromApiMatchCreatedEvents(foundEvents, expectedEvents.reverse()); }); }); @@ -177,7 +173,9 @@ export default function({ getService }: FtrProviderContext) { ) { try { foundEvents.forEach((foundEvent: IValidatedEvent, index: number) => { - expect(foundEvent!.event).to.eql(expectedEvents[index]!.event); + expect(omit(foundEvent!.event ?? {}, 'start', 'end', 'duration')).to.eql( + expectedEvents[index]!.event + ); expect(omit(foundEvent!.kibana ?? {}, 'server_uuid')).to.eql(expectedEvents[index]!.kibana); expect(foundEvent!.message).to.eql(expectedEvents[index]!.message); }); From 43b31dced7cdb3e4d111110c7384d9ae7cdc3ba3 Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Thu, 30 Apr 2020 15:38:33 +0100 Subject: [PATCH 3/4] 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 b9c5dfbb88b3a..869ce1def7cd0 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; + } } From 2dc7de45258f921d2656c0681ed62cc11854a646 Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Thu, 30 Apr 2020 16:55:55 +0100 Subject: [PATCH 4/4] reenable tests --- .../test_suites/event_log/public_api_integration.ts | 4 +--- 1 file changed, 1 insertion(+), 3 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 f5cc1cc166ee8..a2ae165986340 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 @@ -19,9 +19,7 @@ export default function({ getService }: FtrProviderContext) { const log = getService('log'); const retry = getService('retry'); - // FLAKY: https://github.com/elastic/kibana/issues/64723 - // FLAKY: https://github.com/elastic/kibana/issues/64812 - describe.skip('Event Log public API', () => { + describe('Event Log public API', () => { it('should allow querying for events by Saved Object', async () => { const id = uuid.v4();