Skip to content

Commit

Permalink
more robust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Jul 2, 2020
1 parent edfe70b commit 40a456d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class AuditTrailClient implements Auditor {

public add(event: AuditableEvent) {
const user = this.deps.getCurrentUser(this.request);
// doesn't use getSpace since it's async operation calling ES
const spaceId = this.deps.getSpaceId(this.request);

this.event$.next({
Expand Down
27 changes: 23 additions & 4 deletions x-pack/test/plugin_functional/test_suites/audit_trail/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ class FileWrapper {
const content = await this.read();
return content.map((l) => JSON.parse(l));
}
// writing in a file is an async operation. we use this method to make sure logs have been written.
async isNotEmpty() {
const content = await this.read();
const line = content[0];
return line.length > 0;
}
}

export default function ({ getPageObjects, getService }: FtrProviderContext) {
const supertest = getService('supertest');
const retry = getService('retry');

describe('Audit trail service', function () {
this.tags('ciGroup7');
Expand All @@ -45,8 +52,11 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
.set('kbn-xsrf', 'foo')
.expect(204);

const content = await logFile.readJSON();
await retry.waitFor('logs event in the dest file', async () => {
return await logFile.isNotEmpty();
});

const content = await logFile.readJSON();
const pingCall = content.find(
(c) => c.meta.scope === 'audit_trail_test/context/as_current_user'
);
Expand All @@ -62,8 +72,11 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
.set('kbn-xsrf', 'foo')
.expect(204);

const content = await logFile.readJSON();
await retry.waitFor('logs event in the dest file', async () => {
return await logFile.isNotEmpty();
});

const content = await logFile.readJSON();
const pingCall = content.find(
(c) => c.meta.scope === 'audit_trail_test/context/as_internal_user'
);
Expand All @@ -79,8 +92,11 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
.set('kbn-xsrf', 'foo')
.expect(204);

const content = await logFile.readJSON();
await retry.waitFor('logs event in the dest file', async () => {
return await logFile.isNotEmpty();
});

const content = await logFile.readJSON();
const pingCall = content.find(
(c) => c.meta.scope === 'audit_trail_test/contract/as_current_user'
);
Expand All @@ -96,8 +112,11 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
.set('kbn-xsrf', 'foo')
.expect(204);

const content = await logFile.readJSON();
await retry.waitFor('logs event in the dest file', async () => {
return await logFile.isNotEmpty();
});

const content = await logFile.readJSON();
const pingCall = content.find(
(c) => c.meta.scope === 'audit_trail_test/contract/as_internal_user'
);
Expand Down

0 comments on commit 40a456d

Please sign in to comment.