Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kibana migrator test kit] Flush logger after running migrations #152818

Merged
merged 3 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ describe('migration v2', () => {
});

it('clean ups if migration fails', async () => {
const { migrator, client } = await setupNextMinor();
migrator.prepareMigrations();
const { runMigrations, client } = await setupNextMinor();

await expect(migrator.runMigrations()).rejects.toThrowErrorMatchingInlineSnapshot(`
await expect(runMigrations()).rejects.toThrowErrorMatchingInlineSnapshot(`
"Unable to complete saved object migrations for the [${defaultKibanaIndex}] index: Migrations failed. Reason: 1 corrupt saved object documents were found: corrupt:2baf4de0-a6d4-11ed-ba5a-39196fc76e60

To allow migrations to proceed, please delete or fix these documents.
Expand Down Expand Up @@ -135,13 +134,12 @@ const setupBaseline = async () => {
},
];

const { migrator: baselineMigrator, client } = await getKibanaMigratorTestKit({
const { runMigrations, client } = await getKibanaMigratorTestKit({
types: typesCurrent,
logFilePath,
});

baselineMigrator.prepareMigrations();
await baselineMigrator.runMigrations();
await runMigrations();

// inject corrupt saved objects directly using esClient
await Promise.all(
Expand Down Expand Up @@ -175,7 +173,7 @@ const setupNextMinor = async () => {
},
];

const { migrator, client } = await getKibanaMigratorTestKit({
return await getKibanaMigratorTestKit({
types: typesNextMinor,
kibanaVersion: nextMinor,
logFilePath,
Expand Down Expand Up @@ -203,6 +201,4 @@ const setupNextMinor = async () => {
},
},
});

return { migrator, client };
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import {
} from '../kibana_migrator_test_kit';
import { delay } from '../test_utils';

// FLAKY: https://github.com/elastic/kibana/issues/152448
describe.skip('when migrating to a new version', () => {
describe('when migrating to a new version', () => {
let esServer: TestElasticsearchUtils['es'];
let esClient: ElasticsearchClient;
let migrator: IKibanaMigrator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import type { ISavedObjectsRepository } from '@kbn/core-saved-objects-api-server
import { getDocLinks, getDocLinksMeta } from '@kbn/doc-links';
import type { DocLinksServiceStart } from '@kbn/core-doc-links-server';
import { baselineDocuments, baselineTypes } from './kibana_migrator_test_kit.fixtures';
import { delay } from './test_utils';

export const defaultLogFilePath = Path.join(__dirname, 'kibana_migrator_test_kit.log');

Expand Down Expand Up @@ -150,7 +149,9 @@ export const getKibanaMigratorTestKit = async ({

const runMigrations = async (rerun?: boolean) => {
migrator.prepareMigrations();
return await migrator.runMigrations({ rerun });
const migrationResults = await migrator.runMigrations({ rerun });
await loggingSystem.stop();
return migrationResults;
};

const savedObjectsRepository = SavedObjectsRepository.createRepository(
Expand Down Expand Up @@ -283,13 +284,12 @@ const registerTypes = (
};

export const createBaseline = async () => {
const { client, migrator, savedObjectsRepository } = await getKibanaMigratorTestKit({
const { client, runMigrations, savedObjectsRepository } = await getKibanaMigratorTestKit({
kibanaIndex: defaultKibanaIndex,
types: baselineTypes,
});

migrator.prepareMigrations();
await migrator.runMigrations();
await runMigrations();

await savedObjectsRepository.bulkCreate(baselineDocuments, {
refresh: 'wait_for',
Expand Down Expand Up @@ -385,7 +385,6 @@ export const getIncompatibleMappingsMigrator = async ({
};

export const readLog = async (logFilePath: string = defaultLogFilePath): Promise<string> => {
await delay(0.1); // give the logger enough time to write to the file
return await fs.readFile(logFilePath, 'utf-8');
};

Expand Down