mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Flaky Tests] Fix event-loop-delay collector's rollup tests (#143350)
This commit is contained in:
parent
accefcbab9
commit
e962e0ebec
1 changed files with 41 additions and 15 deletions
|
@ -6,7 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import type { Logger, ISavedObjectsRepository } from '@kbn/core/server';
|
||||
import type { Logger, ISavedObjectsRepository, SavedObject } from '@kbn/core/server';
|
||||
import {
|
||||
createTestServers,
|
||||
TestElasticsearchUtils,
|
||||
|
@ -25,7 +25,7 @@ import moment from 'moment';
|
|||
|
||||
const eventLoopDelaysMonitor = metricsServiceMock.createEventLoopDelaysMonitor();
|
||||
|
||||
function createRawObject(date: moment.MomentInput) {
|
||||
function createRawObject(date: moment.MomentInput): SavedObject<EventLoopDelaysDaily> {
|
||||
const pid = Math.round(Math.random() * 10000);
|
||||
const instanceUuid = 'mock_instance';
|
||||
|
||||
|
@ -39,26 +39,33 @@ function createRawObject(date: moment.MomentInput) {
|
|||
processId: pid,
|
||||
instanceUuid,
|
||||
},
|
||||
references: [],
|
||||
};
|
||||
}
|
||||
|
||||
const rawEventLoopDelaysDaily = [
|
||||
createRawObject(moment.now()),
|
||||
createRawObject(moment.now()),
|
||||
createRawObject(moment().subtract(1, 'days')),
|
||||
createRawObject(moment().subtract(3, 'days')),
|
||||
];
|
||||
function createRawEventLoopDelaysDailyDocs() {
|
||||
const rawEventLoopDelaysDaily = [
|
||||
createRawObject(moment.now()),
|
||||
createRawObject(moment.now()),
|
||||
createRawObject(moment().subtract(1, 'days')),
|
||||
createRawObject(moment().subtract(3, 'days')),
|
||||
];
|
||||
|
||||
const outdatedRawEventLoopDelaysDaily = [
|
||||
createRawObject(moment().subtract(5, 'days')),
|
||||
createRawObject(moment().subtract(7, 'days')),
|
||||
];
|
||||
const outdatedRawEventLoopDelaysDaily = [
|
||||
createRawObject(moment().subtract(5, 'days')),
|
||||
createRawObject(moment().subtract(7, 'days')),
|
||||
];
|
||||
|
||||
return { rawEventLoopDelaysDaily, outdatedRawEventLoopDelaysDaily };
|
||||
}
|
||||
|
||||
describe(`daily rollups integration test`, () => {
|
||||
let esServer: TestElasticsearchUtils;
|
||||
let root: TestKibanaUtils['root'];
|
||||
let internalRepository: ISavedObjectsRepository;
|
||||
let logger: Logger;
|
||||
let rawEventLoopDelaysDaily: Array<SavedObject<EventLoopDelaysDaily>>;
|
||||
let outdatedRawEventLoopDelaysDaily: Array<SavedObject<EventLoopDelaysDaily>>;
|
||||
|
||||
beforeAll(async () => {
|
||||
const { startES } = createTestServers({
|
||||
|
@ -74,6 +81,20 @@ describe(`daily rollups integration test`, () => {
|
|||
logger = root.logger.get('test daily rollups');
|
||||
internalRepository = start.savedObjects.createInternalRepository([SAVED_OBJECTS_DAILY_TYPE]);
|
||||
|
||||
// If we are less than 1 second away from midnight, let's wait 1 second before creating the docs.
|
||||
// Otherwise, we may receive 1 document less than the expected ones.
|
||||
if (moment().endOf('day').diff(moment(), 's', true) < 1) {
|
||||
logger.info(
|
||||
'Delaying the creation of the docs 1s, just in case we create them before midnight and run the tests on the following day.'
|
||||
);
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
|
||||
// Create the docs now
|
||||
const rawDailyDocs = createRawEventLoopDelaysDailyDocs();
|
||||
rawEventLoopDelaysDaily = rawDailyDocs.rawEventLoopDelaysDaily;
|
||||
outdatedRawEventLoopDelaysDaily = rawDailyDocs.outdatedRawEventLoopDelaysDaily;
|
||||
|
||||
await internalRepository.bulkCreate<EventLoopDelaysDaily>(
|
||||
[...rawEventLoopDelaysDaily, ...outdatedRawEventLoopDelaysDaily],
|
||||
{ refresh: true }
|
||||
|
@ -90,8 +111,13 @@ describe(`daily rollups integration test`, () => {
|
|||
const { total, saved_objects: savedObjects } =
|
||||
await internalRepository.find<EventLoopDelaysDaily>({ type: SAVED_OBJECTS_DAILY_TYPE });
|
||||
expect(total).toBe(rawEventLoopDelaysDaily.length);
|
||||
expect(savedObjects.map(({ id, type, attributes }) => ({ id, type, attributes }))).toEqual(
|
||||
rawEventLoopDelaysDaily
|
||||
);
|
||||
expect(
|
||||
savedObjects.map(({ id, type, attributes, references }) => ({
|
||||
id,
|
||||
type,
|
||||
attributes,
|
||||
references,
|
||||
}))
|
||||
).toEqual(rawEventLoopDelaysDaily);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue