Skip to content

Commit

Permalink
[Event Log] Ensure sorting tests are less flaky (elastic#64781)
Browse files Browse the repository at this point in the history
Creating events in parallel may be causing a slight flakyness, this change staggers creation to ensure this doesn't happen.
In addition it turned out the `event.end` field was missing in certain cases, causing the test that sorts by `end` to fail.
  • Loading branch information
gmmorris committed May 4, 2020
1 parent 445d703 commit 78a3bce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ${id}`);
}
// mark now as start and end
eventLogger.startTiming(event);
eventLogger.stopTiming(event);
eventLogger.logEvent(event);
logger.info(`logged`);
return res.ok({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -82,21 +80,15 @@ 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);
await Promise.all(expectedEvents.map(event => logTestEvent(id, event)));
const expectedEvents = await logFakeEvents(id, 6);

await retry.try(async () => {
const {
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());
});
});

Expand All @@ -112,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();
Expand Down Expand Up @@ -176,7 +167,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);
});
Expand Down Expand Up @@ -217,4 +210,14 @@ export default function({ getService }: FtrProviderContext) {
overrides
);
}

async function logFakeEvents(savedObjectId: string, eventsToLog: number): Promise<IEvent[]> {
const expectedEvents: IEvent[] = [];
for (let index = 0; index < eventsToLog; index++) {
const event = fakeEvent(savedObjectId);
await logTestEvent(savedObjectId, event);
expectedEvents.push(event);
}
return expectedEvents;
}
}

0 comments on commit 78a3bce

Please sign in to comment.