[Event Log] Ensure sorting tests are less flaky (#64781)
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.
This commit is contained in:
parent
3356a19294
commit
9cfe4cf659
|
@ -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({});
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
@ -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());
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue