From 471fe080484f937a6c52b653c37ff69d44a0a85c Mon Sep 17 00:00:00 2001 From: Gidi Meir Morris Date: Thu, 30 Apr 2020 11:18:16 +0100 Subject: [PATCH] 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); });