Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf committed Dec 15, 2020
1 parent 11dc7cf commit e815df4
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ describe('KibanaMigrator', () => {
// LEGACY_CREATE_REINDEX_TARGET
expect.arrayContaining([expect.objectContaining({ index: '.my-index_pre8.2.3_001' })]),
// CREATE_REINDEX_TEMP
expect.arrayContaining([expect.objectContaining({ index: '.my-index_8.2.3_001' })]),
expect.arrayContaining([
expect.objectContaining({ index: '.my-index_8.2.3_reindex_temp' }),
]),
// CREATE_NEW_TARGET
expect.arrayContaining([expect.objectContaining({ index: 'other-index_8.2.3_001' })]),
])
Expand All @@ -199,7 +201,7 @@ describe('KibanaMigrator', () => {
expect.objectContaining({
body: expect.objectContaining({
source: expect.objectContaining({ index: '.my-index_pre8.2.3_001' }),
dest: expect.objectContaining({ index: '.my-index_8.2.3_001' }),
dest: expect.objectContaining({ index: '.my-index_8.2.3_reindex_temp' }),
}),
})
);
Expand Down Expand Up @@ -262,9 +264,10 @@ describe('KibanaMigrator', () => {

const migrator = new KibanaMigrator(options);

await expect(migrator.runMigrations()).rejects.toMatchInlineSnapshot(
`[Error: Unable to complete saved object migrations for the [.my-index] index. Please check the health of your Elasticsearch cluster and try again.]`
);
await expect(migrator.runMigrations()).rejects.toMatchInlineSnapshot(`
[Error: Unable to complete saved object migrations for the [.my-index] index. Please check the health of your Elasticsearch cluster and try again. Error: Reindex failed with the following error:
{"_tag":"Some","value":{"type":"elatsicsearch_exception","reason":"task failed with an error"}}]
`);
expect(loggingSystemMock.collect(options.logger).error[0][0]).toMatchInlineSnapshot(`
[Error: Reindex failed with the following error:
{"_tag":"Some","value":{"type":"elatsicsearch_exception","reason":"task failed with an error"}}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,13 @@ describe('migrationsStateActionMachine', () => {
"_tag": "None",
},
"reason": "the fatal reason",
"reindexAlias": ".my-so-index_7.11.0_reindex",
"reindexTargetMappings": Object {
"retryCount": 0,
"retryDelay": 0,
"targetIndexMappings": Object {
"properties": Object {},
},
"tempIndex": ".my-so-index_7.11.0_reindex_temp",
"tempIndexMappings": Object {
"dynamic": false,
"properties": Object {
"migrationVersion": Object {
Expand All @@ -245,11 +250,6 @@ describe('migrationsStateActionMachine', () => {
},
},
},
"retryCount": 0,
"retryDelay": 0,
"targetMappings": Object {
"properties": Object {},
},
"versionAlias": ".my-so-index_7.11.0",
"versionIndex": ".my-so-index_7.11.0_001",
},
Expand Down Expand Up @@ -291,8 +291,13 @@ describe('migrationsStateActionMachine', () => {
"_tag": "None",
},
"reason": "the fatal reason",
"reindexAlias": ".my-so-index_7.11.0_reindex",
"reindexTargetMappings": Object {
"retryCount": 0,
"retryDelay": 0,
"targetIndexMappings": Object {
"properties": Object {},
},
"tempIndex": ".my-so-index_7.11.0_reindex_temp",
"tempIndexMappings": Object {
"dynamic": false,
"properties": Object {
"migrationVersion": Object {
Expand All @@ -304,11 +309,6 @@ describe('migrationsStateActionMachine', () => {
},
},
},
"retryCount": 0,
"retryDelay": 0,
"targetMappings": Object {
"properties": Object {},
},
"versionAlias": ".my-so-index_7.11.0",
"versionIndex": ".my-so-index_7.11.0_001",
},
Expand Down Expand Up @@ -430,8 +430,13 @@ describe('migrationsStateActionMachine', () => {
"_tag": "None",
},
"reason": "the fatal reason",
"reindexAlias": ".my-so-index_7.11.0_reindex",
"reindexTargetMappings": Object {
"retryCount": 0,
"retryDelay": 0,
"targetIndexMappings": Object {
"properties": Object {},
},
"tempIndex": ".my-so-index_7.11.0_reindex_temp",
"tempIndexMappings": Object {
"dynamic": false,
"properties": Object {
"migrationVersion": Object {
Expand All @@ -443,11 +448,6 @@ describe('migrationsStateActionMachine', () => {
},
},
},
"retryCount": 0,
"retryDelay": 0,
"targetMappings": Object {
"properties": Object {},
},
"versionAlias": ".my-so-index_7.11.0",
"versionIndex": ".my-so-index_7.11.0_001",
},
Expand Down Expand Up @@ -484,8 +484,13 @@ describe('migrationsStateActionMachine', () => {
"_tag": "None",
},
"reason": "the fatal reason",
"reindexAlias": ".my-so-index_7.11.0_reindex",
"reindexTargetMappings": Object {
"retryCount": 0,
"retryDelay": 0,
"targetIndexMappings": Object {
"properties": Object {},
},
"tempIndex": ".my-so-index_7.11.0_reindex_temp",
"tempIndexMappings": Object {
"dynamic": false,
"properties": Object {
"migrationVersion": Object {
Expand All @@ -497,11 +502,6 @@ describe('migrationsStateActionMachine', () => {
},
},
},
"retryCount": 0,
"retryDelay": 0,
"targetMappings": Object {
"properties": Object {},
},
"versionAlias": ".my-so-index_7.11.0",
"versionIndex": ".my-so-index_7.11.0_001",
},
Expand Down
23 changes: 21 additions & 2 deletions src/core/server/saved_objects/migrationsv2/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('migrations v2 model', () => {
currentAlias: '.kibana',
versionAlias: '.kibana_7.11.0',
versionIndex: '.kibana_7.11.0_001',
tempIndex: '.kibana_7.11.0_reindex',
tempIndex: '.kibana_7.11.0_reindex_temp',
};

describe('exponential retry delays for retryable_es_client_error', () => {
Expand Down Expand Up @@ -684,6 +684,25 @@ describe('migrations v2 model', () => {
expect(newState.retryCount).toEqual(0);
expect(newState.retryDelay).toEqual(0);
});
test('REINDEX_SOURCE_TO_TEMP_WAIT_FOR_TASK -> SET_TEMP_WRITE_BLOCK when response is left target_index_had_write_block', () => {
const res: ResponseType<'REINDEX_SOURCE_TO_TEMP_WAIT_FOR_TASK'> = Either.left({
type: 'target_index_had_write_block',
});
const newState = model(state, res);
expect(newState.controlState).toEqual('SET_TEMP_WRITE_BLOCK');
expect(newState.retryCount).toEqual(0);
expect(newState.retryDelay).toEqual(0);
});
test('REINDEX_SOURCE_TO_TEMP_WAIT_FOR_TASK -> SET_TEMP_WRITE_BLOCK when response is left index_not_found_exception', () => {
const res: ResponseType<'REINDEX_SOURCE_TO_TEMP_WAIT_FOR_TASK'> = Either.left({
type: 'index_not_found_exception',
index: '.kibana_7.11.0_reindex_temp',
});
const newState = model(state, res);
expect(newState.controlState).toEqual('SET_TEMP_WRITE_BLOCK');
expect(newState.retryCount).toEqual(0);
expect(newState.retryDelay).toEqual(0);
});
});
describe('SET_TEMP_WRITE_BLOCK', () => {
const state: SetTempWriteBlock = {
Expand Down Expand Up @@ -1013,7 +1032,7 @@ describe('migrations v2 model', () => {
},
},
},
"tempIndex": ".kibana_task_manager_8.1.0_temp",
"tempIndex": ".kibana_task_manager_8.1.0_reindex_temp",
"tempIndexMappings": Object {
"dynamic": false,
"properties": Object {
Expand Down
13 changes: 9 additions & 4 deletions src/core/server/saved_objects/migrationsv2/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,16 @@ export const model = (currentState: State, resW: ResponseType<AllActionStates>):
};
} else {
const left = res.left;
if (left.type === 'index_not_found_exception' && left.index === stateP.tempIndex) {
if (
left.type === 'target_index_had_write_block' ||
(left.type === 'index_not_found_exception' && left.index === stateP.tempIndex)
) {
// index_not_found_exception:
// another instance completed the MARK_VERSION_INDEX_READY and
// removed the temp index.
// target_index_had_write_block
// another instance completed the SET_TEMP_WRITE_BLOCK step adding a
// write block to the temp index.
//
// For simplicity we continue linearly through the next steps even if
// we know another instance already completed these.
Expand All @@ -498,8 +504,7 @@ export const model = (currentState: State, resW: ResponseType<AllActionStates>):
controlState: 'SET_TEMP_WRITE_BLOCK',
};
} else {
// Don't handle target_index_had_write_block and
// incompatible_mapping_exception as we will never add a write
// Don't handle incompatible_mapping_exception as we will never add a write
// block to the temp index or change the mappings.
throwBadResponse(stateP, left as never);
}
Expand Down Expand Up @@ -743,7 +748,7 @@ export const createInitialState = ({
currentAlias: indexPrefix,
versionAlias: `${indexPrefix}_${kibanaVersion}`,
versionIndex: `${indexPrefix}_${kibanaVersion}_001`,
tempIndex: `${indexPrefix}_${kibanaVersion}_temp`,
tempIndex: `${indexPrefix}_${kibanaVersion}_reindex_temp`,
kibanaVersion,
preMigrationScript: Option.fromNullable(preMigrationScript),
targetIndexMappings: targetMappings,
Expand Down

0 comments on commit e815df4

Please sign in to comment.