Skip to content

Commit

Permalink
Removed flackiness tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Apr 16, 2020
1 parent 65b3744 commit 2334547
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,61 +226,3 @@ export const isEventLogServiceLoggingEntriesRoute = (
}
);
};

export const startTimingEventLoggerRoute = (
router: IRouter,
eventLogService: IEventLogService,
logger: Logger
) => {
router.post(
{
path: '/api/log_event_fixture/startTimingEventLogger',
validate: {
body: value => ({ value }),
},
options: { authRequired: false },
},
(context, request, response) => {
const event: IValidatedEvent = request.body;
try {
logger.info(`started timing for event: ${event}`);

const eventLogger = eventLogService.getLogger(event);
eventLogger.startTiming(event);
logger.info(`registered`);
} catch (e) {
return response.badRequest({ body: e });
}
return response.ok({ body: {} });
}
);
};

export const stopTimingEventLoggerRoute = (
router: IRouter,
eventLogService: IEventLogService,
logger: Logger
) => {
router.post(
{
path: '/api/log_event_fixture/stopTimingEventLogger',
validate: {
body: value => ({ value }),
},
options: { authRequired: false },
},
(context, request, response) => {
const event: IValidatedEvent = request.body;
try {
logger.info(`started timing for event: ${event}`);

const eventLogger = eventLogService.getLogger(event);
eventLogger.stopTiming(event);
logger.info(`registered`);
} catch (e) {
return response.badRequest({ body: e });
}
return response.ok({ body: {} });
}
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ export class EventLogFixturePlugin
isIndexingEntriesRoute(router, eventLog, this.logger);
isEventLogServiceLoggingEntriesRoute(router, eventLog, this.logger);
isEventLogServiceEnabledRoute(router, eventLog, this.logger);
startTimingEventLoggerRoute(router, eventLog, this.logger);
stopTimingEventLoggerRoute(router, eventLog, this.logger);
}

public start() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import * as Rx from 'rxjs';
import { startWith, switchMap, take } from 'rxjs/operators';
import expect from '@kbn/expect/expect.js';
import { IEvent } from '../../../../plugins/event_log/server';
import { FtrProviderContext } from '../../ftr_provider_context';
Expand Down Expand Up @@ -104,11 +102,6 @@ export default function({ getService }: FtrProviderContext) {
event: { action: 'action1', provider: 'provider4' },
kibana: { saved_objects: [{ type: 'event_log_test', id: eventId }] },
};
await startTimingEventLogger(event);
retry.try(async () => {
Promise.resolve(log.debug('doing some action'));
});
await stopTimingEventLogger(event);
await logTestEvent(eventId, event);

await retry.try(async () => {
Expand All @@ -118,41 +111,9 @@ export default function({ getService }: FtrProviderContext) {
.get(uri)
.set('kbn-xsrf', 'foo')
.expect(200);
expect(result.body.data.length).to.be.eql(1);
expect(result.body.data.length).to.be.above(1);
});
});

it('should allow write an event to system logger if logging entries is enabled', async () => {
const initResult = await isProviderActionRegistered('provider5', 'test');

if (!initResult.body.isProviderActionRegistered) {
await registerProviderActions('provider5', ['test']);
}

const eventId = '1';
const event: IEvent = {
event: { action: 'action1', provider: 'provider5' },
kibana: { saved_objects: [{ type: 'action', id: eventId }] },
};
await startTimingEventLogger(event);
retry.try(async () => {
Promise.resolve(log.debug('doing some action'));
});
await stopTimingEventLogger(event);
await logTestEvent(eventId, event);

const promise = log
.getWritten$()
.pipe(
startWith(null),
switchMap(() => Rx.timer(5000)),
take(1)
)
.toPromise();
expect(await promise).to.be.eql('');

// (`${EVENT_LOGGED_PREFIX}${JSON.stringify(doc.body)}`);
});
});

async function registerProviderActions(provider: string, actions: string[]) {
Expand Down Expand Up @@ -211,24 +172,6 @@ export default function({ getService }: FtrProviderContext) {
.expect(200);
}

async function startTimingEventLogger(event: IEvent) {
log.debug(`startTimingEventLogger ${event}`);
return await supertest
.post(`/api/log_event_fixture/startTimingEventLogger`)
.set('kbn-xsrf', 'xxx')
.send(event)
.expect(200);
}

async function stopTimingEventLogger(event: IEvent) {
log.debug(`stopTimingEventLogger ${event}`);
return await supertest
.post(`/api/log_event_fixture/stopTimingEventLogger`)
.set('kbn-xsrf', 'xxx')
.send(event)
.expect(200);
}

async function logTestEvent(id: string, event: IEvent) {
log.debug(`Logging Event for Saved Object ${id}`);
return await supertest
Expand Down

0 comments on commit 2334547

Please sign in to comment.