Skip to content

Commit

Permalink
Unskip flaky test; Add retry when parsing JSON from audit log (#132510)
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego authored May 19, 2022
1 parent 3f339f2 commit d9e6ef3
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions x-pack/test/security_api_integration/tests/audit/audit_log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import Path from 'path';
import Fs from 'fs';
import expect from '@kbn/expect';
import { RetryService } from '../../../../../test/common/services/retry';
import { FtrProviderContext } from '../../ftr_provider_context';

class FileWrapper {
constructor(private readonly path: string) {}
constructor(private readonly path: string, private readonly retry: RetryService) {}
async reset() {
// "touch" each file to ensure it exists and is empty before each test
await Fs.promises.writeFile(this.path, '');
Expand All @@ -21,15 +22,17 @@ class FileWrapper {
return content.trim().split('\n');
}
async readJSON() {
const content = await this.read();
try {
return content.map((l) => JSON.parse(l));
} catch (err) {
const contentString = content.join('\n');
throw new Error(
`Failed to parse audit log JSON, error: "${err.message}", audit.log contents:\n${contentString}`
);
}
return this.retry.try(async () => {
const content = await this.read();
try {
return content.map((l) => JSON.parse(l));
} catch (err) {
const contentString = content.join('\n');
throw new Error(
`Failed to parse audit log JSON, error: "${err.message}", audit.log contents:\n${contentString}`
);
}
});
}
// writing in a file is an async operation. we use this method to make sure logs have been written.
async isNotEmpty() {
Expand All @@ -44,10 +47,9 @@ export default function ({ getService }: FtrProviderContext) {
const retry = getService('retry');
const { username, password } = getService('config').get('servers.kibana');

// FLAKY: https://github.com/elastic/kibana/issues/119267
describe.skip('Audit Log', function () {
describe('Audit Log', function () {
const logFilePath = Path.resolve(__dirname, '../../fixtures/audit/audit.log');
const logFile = new FileWrapper(logFilePath);
const logFile = new FileWrapper(logFilePath, retry);

beforeEach(async () => {
await logFile.reset();
Expand Down

0 comments on commit d9e6ef3

Please sign in to comment.