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

Attempt to stabilize cloneIndex integration tests #86123

Merged
merged 7 commits into from
Dec 18, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe('migration actions', () => {

describe('fetchIndices', () => {
it('resolves right empty record if no indices were found', async () => {
expect.assertions(1);
const task = fetchIndices(client, ['no_such_index']);
return expect(task()).resolves.toMatchInlineSnapshot(`
Object {
rudolf marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -109,6 +110,7 @@ describe('migration actions', () => {
`);
});
it('resolves right record with found indices', async () => {
expect.assertions(1);
const res = (await fetchIndices(client, [
'no_such_index',
'existing_index_with_docs',
Expand All @@ -131,6 +133,7 @@ describe('migration actions', () => {
await createIndex(client, 'new_index_without_write_block', { properties: {} })();
});
it('resolves right when setting the write block succeeds', async () => {
expect.assertions(1);
const task = setWriteBlock(client, 'new_index_without_write_block');
return expect(task()).resolves.toMatchInlineSnapshot(`
Object {
Expand All @@ -140,6 +143,7 @@ describe('migration actions', () => {
`);
});
it('resolves right when setting a write block on an index that already has one', () => {
expect.assertions(1);
const task = setWriteBlock(client, 'existing_index_with_write_block');
return expect(task()).resolves.toMatchInlineSnapshot(`
Object {
Expand All @@ -149,6 +153,7 @@ describe('migration actions', () => {
`);
});
it('once resolved, prevents further writes to the index', async () => {
expect.assertions(1);
const task = setWriteBlock(client, 'new_index_without_write_block');
await task();
const sourceDocs = ([
Expand All @@ -162,6 +167,7 @@ describe('migration actions', () => {
).rejects.toMatchObject(expect.anything());
});
it('resolves left index_not_found_exception when the index does not exist', () => {
expect.assertions(1);
const task = setWriteBlock(client, 'no_such_index');
return expect(task()).resolves.toMatchInlineSnapshot(`
Object {
Expand All @@ -181,6 +187,7 @@ describe('migration actions', () => {
await setWriteBlock(client, 'existing_index_with_write_block_2')();
});
it('resolves right if successful when an index already has a write block', () => {
expect.assertions(1);
const task = removeWriteBlock(client, 'existing_index_with_write_block_2');
return expect(task()).resolves.toMatchInlineSnapshot(`
Object {
Expand All @@ -190,6 +197,7 @@ describe('migration actions', () => {
`);
});
it('resolves right if successful when an index does not have a write block', () => {
expect.assertions(1);
const task = removeWriteBlock(client, 'existing_index_without_write_block_2');
return expect(task()).resolves.toMatchInlineSnapshot(`
Object {
Expand All @@ -199,6 +207,7 @@ describe('migration actions', () => {
`);
});
it('rejects if there is a non-retryable error', () => {
expect.assertions(1);
const task = removeWriteBlock(client, 'no_such_index');
return expect(task()).rejects.toMatchInlineSnapshot(
`[ResponseError: index_not_found_exception]`
Expand All @@ -207,16 +216,21 @@ describe('migration actions', () => {
});

describe('cloneIndex', () => {
afterEach(async () => {
afterAll(async () => {
try {
await client.indices.delete({ index: 'yellow_then_green_index' });
await client.indices.delete({ index: 'clone_*' });
} catch (e) {
/** ignore */
}
});
it('resolves right if cloning into a new target index', () => {
const task = cloneIndex(client, 'existing_index_with_write_block', 'yellow_then_green_index');
expect(task()).resolves.toMatchInlineSnapshot(`
expect.assertions(1);
const task = cloneIndex(
client,
'existing_index_with_write_block',
'clone_yellow_then_green_index_1'
);
return expect(task()).resolves.toMatchInlineSnapshot(`
Object {
"_tag": "Right",
"right": Object {
Expand All @@ -226,10 +240,11 @@ describe('migration actions', () => {
}
`);
});
it.skip('resolves right after waiting for index status to be green if clone target already existed', async () => {
it('resolves right after waiting for index status to be green if clone target already existed', async () => {
expect.assertions(2);
// Create a yellow index
await client.indices.create({
index: 'yellow_then_green_index',
index: 'clone_yellow_then_green_index_2',
body: {
mappings: { properties: {} },
settings: {
Expand All @@ -243,7 +258,7 @@ describe('migration actions', () => {
const cloneIndexPromise = cloneIndex(
client,
'existing_index_with_write_block',
'yellow_then_green_index'
'clone_yellow_then_green_index_2'
)();
let indexGreen = false;

Expand Down Expand Up @@ -273,8 +288,9 @@ describe('migration actions', () => {
});
});
it('resolves left index_not_found_exception if the source index does not exist', () => {
const task = cloneIndex(client, 'no_such_index', 'yellow_then_green_index');
expect(task()).resolves.toMatchInlineSnapshot(`
expect.assertions(1);
const task = cloneIndex(client, 'no_such_index', 'clone_yellow_then_green_index_3');
return expect(task()).resolves.toMatchInlineSnapshot(`
Object {
"_tag": "Left",
"left": Object {
Expand All @@ -289,6 +305,7 @@ describe('migration actions', () => {
// Reindex doesn't return any errors on it's own, so we have to test
// together with waitForReindexTask
describe('reindex & waitForReindexTask', () => {
expect.assertions(2);
it('resolves right when reindex succeeds without reindex script', async () => {
const res = (await reindex(
client,
Expand Down Expand Up @@ -320,6 +337,7 @@ describe('migration actions', () => {
`);
});
it('resolves right when reindex succeeds with reindex script', async () => {
expect.assertions(2);
const res = (await reindex(
client,
'existing_index_with_docs',
Expand Down Expand Up @@ -349,6 +367,7 @@ describe('migration actions', () => {
`);
});
it('resolves right, ignores version conflicts and does not update existing docs when reindex multiple times', async () => {
expect.assertions(3);
// Reindex with a script
let res = (await reindex(
client,
Expand Down Expand Up @@ -397,6 +416,7 @@ describe('migration actions', () => {
`);
});
it('resolves right and proceeds to add missing documents if there are some existing docs conflicts', async () => {
expect.assertions(2);
// Simulate a reindex that only adds some of the documents from the
// source index into the target index
await createIndex(client, 'reindex_target_4', { properties: {} })();
Expand Down Expand Up @@ -444,6 +464,7 @@ describe('migration actions', () => {
`);
});
it('resolves left incompatible_mapping_exception if all reindex failures are due to a strict_dynamic_mapping_exception', async () => {
expect.assertions(1);
// Simulates one instance having completed the UPDATE_TARGET_MAPPINGS
// step which makes the mappings incompatible with outdated documents.
// If another instance then tries a reindex it will get a
Expand Down Expand Up @@ -479,6 +500,7 @@ describe('migration actions', () => {
`);
});
it('resolves left incompatible_mapping_exception if all reindex failures are due to a mapper_parsing_exception', async () => {
expect.assertions(1);
// Simulates one instance having completed the UPDATE_TARGET_MAPPINGS
// step which makes the mappings incompatible with outdated documents.
// If another instance then tries a reindex it will get a
Expand Down Expand Up @@ -512,6 +534,7 @@ describe('migration actions', () => {
`);
});
it('resolves left index_not_found_exception if source index does not exist', async () => {
expect.assertions(1);
const res = (await reindex(
client,
'no_such_index',
Expand All @@ -531,6 +554,7 @@ describe('migration actions', () => {
`);
});
it('resolves left target_index_had_write_block if all failures are due to a write block', async () => {
expect.assertions(1);
const res = (await reindex(
client,
'existing_index_with_docs',
Expand All @@ -551,6 +575,7 @@ describe('migration actions', () => {
`);
});
it('resolves left if requireAlias=true and the target is not an alias', async () => {
expect.assertions(1);
const res = (await reindex(
client,
'existing_index_with_docs',
Expand All @@ -574,6 +599,7 @@ describe('migration actions', () => {
});

describe('verifyReindex', () => {
expect.assertions(1);
it('resolves right if source and target indices have the same amount of documents', async () => {
const res = (await reindex(
client,
Expand All @@ -593,6 +619,7 @@ describe('migration actions', () => {
`);
});
it('resolves left if source and target indices have different amount of documents', () => {
expect.assertions(1);
const task = verifyReindex(client, 'existing_index_with_docs', 'existing_index_2');
return expect(task()).resolves.toMatchInlineSnapshot(`
Object {
Expand All @@ -604,6 +631,7 @@ describe('migration actions', () => {
`);
});
it('rejects if source or target index does not exist', async () => {
expect.assertions(2);
let task = verifyReindex(client, 'no_such_index', 'existing_index_2');
await expect(task()).rejects.toMatchInlineSnapshot(
`[ResponseError: index_not_found_exception]`
Expand All @@ -618,6 +646,7 @@ describe('migration actions', () => {

describe('searchForOutdatedDocuments', () => {
it('only returns documents that match the outdatedDocumentsQuery', async () => {
expect.assertions(2);
const resultsWithQuery = ((await searchForOutdatedDocuments(
client,
'existing_index_with_docs',
Expand All @@ -635,6 +664,7 @@ describe('migration actions', () => {
expect(resultsWithoutQuery.length).toBe(4);
});
it('resolves with _id, _source, _seq_no and _primary_term', async () => {
expect.assertions(1);
const results = ((await searchForOutdatedDocuments(client, 'existing_index_with_docs', {
match: { title: { query: 'doc' } },
})()) as Either.Right<SearchResponse>).right.outdatedDocuments;
Expand All @@ -655,6 +685,7 @@ describe('migration actions', () => {

describe('waitForPickupUpdatedMappingsTask', () => {
it('rejects if there are failures', async () => {
expect.assertions(1);
const res = (await pickupUpdatedMappings(
client,
'existing_index_with_write_block'
Expand All @@ -669,6 +700,7 @@ describe('migration actions', () => {
});
});
it('rejects if there is an error', async () => {
expect.assertions(1);
const res = (await pickupUpdatedMappings(
client,
'no_such_index'
Expand All @@ -682,6 +714,7 @@ describe('migration actions', () => {
`);
});
it('resolves right when successful', async () => {
expect.assertions(1);
const res = (await pickupUpdatedMappings(
client,
'existing_index_with_docs'
Expand All @@ -700,6 +733,7 @@ describe('migration actions', () => {

describe('updateAndPickupMappings', () => {
it('resolves right when mappings were updated and picked up', async () => {
expect.assertions(3);
// Create an index without any mappings and insert documents into it
await createIndex(client, 'existing_index_without_mappings', {
dynamic: false as any,
Expand Down Expand Up @@ -748,6 +782,7 @@ describe('migration actions', () => {
describe('updateAliases', () => {
describe('remove', () => {
it('resolves left index_not_found_exception when the index does not exist', () => {
expect.assertions(1);
const task = updateAliases(client, [
{
remove: {
Expand All @@ -769,6 +804,7 @@ describe('migration actions', () => {
});
describe('with must_exist=false', () => {
it('resolves left alias_not_found_exception when alias does not exist', async () => {
expect.assertions(1);
const task = updateAliases(client, [
{
remove: {
Expand All @@ -790,6 +826,7 @@ describe('migration actions', () => {
});
describe('with must_exist=true', () => {
it('resolves left alias_not_found_exception when alias does not exist on specified index', async () => {
expect.assertions(1);
const task = updateAliases(client, [
{
remove: {
Expand All @@ -809,6 +846,7 @@ describe('migration actions', () => {
`);
});
it('resolves left alias_not_found_exception when alias does not exist', async () => {
expect.assertions(1);
const task = updateAliases(client, [
{
remove: {
Expand All @@ -831,6 +869,7 @@ describe('migration actions', () => {
});
describe('remove_index', () => {
it('left index_not_found_exception if index does not exist', () => {
expect.assertions(1);
const task = updateAliases(client, [
{
remove_index: {
Expand All @@ -849,6 +888,7 @@ describe('migration actions', () => {
`);
});
it('left remove_index_not_a_concrete_index when remove_index targets an alias', () => {
expect.assertions(1);
const task = updateAliases(client, [
{
remove_index: {
Expand All @@ -872,7 +912,8 @@ describe('migration actions', () => {
afterAll(async () => {
await client.indices.delete({ index: 'yellow_then_green_index' });
});
it.skip('resolves right after waiting for an index status to be green if the index already existed', async () => {
it('resolves right after waiting for an index status to be green if the index already existed', async () => {
expect.assertions(2);
// Create a yellow index
await client.indices.create(
{
Expand Down Expand Up @@ -915,16 +956,18 @@ describe('migration actions', () => {
});
});
it('rejects when there is an unexpected error creating the index', () => {
expect.assertions(1);
// Creating an index with the same name as an existing alias to induce
// failure
expect(
return expect(
createIndex(client, 'existing_index_2_alias', undefined as any)()
).rejects.toMatchInlineSnapshot(`[ResponseError: invalid_index_name_exception]`);
});
});

describe('bulkOverwriteTransformedDocuments', () => {
it('resolves right when documents do not yet exist in the index', () => {
expect.assertions(1);
const newDocs = ([
{ _source: { title: 'doc 5' } },
{ _source: { title: 'doc 6' } },
Expand All @@ -939,6 +982,7 @@ describe('migration actions', () => {
`);
});
it('resolves right even if there were some version_conflict_engine_exception', async () => {
expect.assertions(1);
const existingDocs = ((await searchForOutdatedDocuments(
client,
'existing_index_with_docs',
Expand All @@ -957,6 +1001,7 @@ describe('migration actions', () => {
`);
});
it('rejects if there are errors', () => {
expect.assertions(1);
const newDocs = ([
{ _source: { title: 'doc 5' } },
{ _source: { title: 'doc 6' } },
Expand Down