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

[7.9] [Ingest Manager] prevent crash on unhandled rejection from setupIngestManager (#74300) #74350

Merged
merged 1 commit into from
Aug 5, 2020
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
44 changes: 44 additions & 0 deletions x-pack/plugins/ingest_manager/server/services/setup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { setupIngestManager } from './setup';
import { savedObjectsClientMock } from 'src/core/server/mocks';

describe('setupIngestManager', () => {
it('returned promise should reject if errors thrown', async () => {
const { savedObjectsClient, callClusterMock } = makeErrorMocks();
const setupPromise = setupIngestManager(savedObjectsClient, callClusterMock);
await expect(setupPromise).rejects.toThrow('mocked');
});
});

function makeErrorMocks() {
jest.mock('./app_context'); // else fails w/"Logger not set."
jest.mock('./epm/registry/registry_url', () => {
return {
fetchUrl: () => {
throw new Error('mocked registry#fetchUrl');
},
};
});

const callClusterMock = jest.fn();
const savedObjectsClient = savedObjectsClientMock.create();
savedObjectsClient.find = jest.fn().mockImplementation(() => {
throw new Error('mocked SO#find');
});
savedObjectsClient.get = jest.fn().mockImplementation(() => {
throw new Error('mocked SO#get');
});
savedObjectsClient.update = jest.fn().mockImplementation(() => {
throw new Error('mocked SO#update');
});

return {
savedObjectsClient,
callClusterMock,
};
}
5 changes: 5 additions & 0 deletions x-pack/plugins/ingest_manager/server/services/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ export async function setupIngestManager(
// if anything errors, reject/fail
onSetupReject(error);
}

// be sure to return the promise because it has the resolved/rejected status attached to it
// otherwise, we effectively return success every time even if there are errors
// because `return undefined` -> `Promise.resolve(undefined)` in an `async` function
return setupIngestStatus;
}

export async function setupFleet(
Expand Down