mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Make stop method of the taskManager plugin async (#191218)
towards: https://github.com/elastic/kibana/issues/189306 This PR fixes the `Deleting current node has failed.`errors mentioned in the above issue.
This commit is contained in:
parent
74a9c1991b
commit
5dfa3ecf58
4 changed files with 32 additions and 22 deletions
|
@ -193,19 +193,5 @@ describe('KibanaDiscoveryService', () => {
|
|||
'Removed this node from the Kibana Discovery Service'
|
||||
);
|
||||
});
|
||||
|
||||
it('logs an error when failed', async () => {
|
||||
savedObjectsRepository.delete.mockRejectedValue(new Error('bar'));
|
||||
|
||||
const kibanaDiscoveryService = new KibanaDiscoveryService({
|
||||
savedObjectsRepository,
|
||||
logger,
|
||||
currentNode,
|
||||
});
|
||||
|
||||
await kibanaDiscoveryService.deleteCurrentNode();
|
||||
|
||||
expect(logger.error).toHaveBeenCalledWith('Deleting current node has failed. error: bar');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -100,11 +100,7 @@ export class KibanaDiscoveryService {
|
|||
}
|
||||
|
||||
public async deleteCurrentNode() {
|
||||
try {
|
||||
await this.savedObjectsRepository.delete(BACKGROUND_TASK_NODE_SO_NAME, this.currentNode);
|
||||
this.logger.info('Removed this node from the Kibana Discovery Service');
|
||||
} catch (e) {
|
||||
this.logger.error(`Deleting current node has failed. error: ${e.message}`);
|
||||
}
|
||||
await this.savedObjectsRepository.delete(BACKGROUND_TASK_NODE_SO_NAME, this.currentNode);
|
||||
this.logger.info('Removed this node from the Kibana Discovery Service');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
|
||||
import { TaskManagerPlugin, getElasticsearchAndSOAvailability } from './plugin';
|
||||
import { KibanaDiscoveryService } from './kibana_discovery_service';
|
||||
|
||||
import { coreMock } from '@kbn/core/server/mocks';
|
||||
import { TaskManagerConfig } from './config';
|
||||
import { Subject } from 'rxjs';
|
||||
|
@ -37,6 +39,9 @@ jest.mock('./ephemeral_task_lifecycle', () => {
|
|||
};
|
||||
});
|
||||
|
||||
const deleteCurrentNodeSpy = jest.spyOn(KibanaDiscoveryService.prototype, 'deleteCurrentNode');
|
||||
const discoveryIsStarted = jest.spyOn(KibanaDiscoveryService.prototype, 'isStarted');
|
||||
|
||||
const coreStart = coreMock.createStart();
|
||||
const pluginInitializerContextParams = {
|
||||
max_attempts: 9,
|
||||
|
@ -176,6 +181,25 @@ describe('TaskManagerPlugin', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('stop', () => {
|
||||
test('should remove the current from discovery service', async () => {
|
||||
const pluginInitializerContext = coreMock.createPluginInitializerContext<TaskManagerConfig>(
|
||||
pluginInitializerContextParams
|
||||
);
|
||||
pluginInitializerContext.node.roles.backgroundTasks = true;
|
||||
const taskManagerPlugin = new TaskManagerPlugin(pluginInitializerContext);
|
||||
taskManagerPlugin.setup(coreMock.createSetup(), { usageCollection: undefined });
|
||||
taskManagerPlugin.start(coreStart, {
|
||||
cloud: cloudMock.createStart(),
|
||||
});
|
||||
|
||||
discoveryIsStarted.mockReturnValueOnce(true);
|
||||
await taskManagerPlugin.stop();
|
||||
|
||||
expect(deleteCurrentNodeSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getElasticsearchAndSOAvailability', () => {
|
||||
test('returns true when both services are available', async () => {
|
||||
const core$ = new Subject<CoreStatus>();
|
||||
|
|
|
@ -395,9 +395,13 @@ export class TaskManagerPlugin
|
|||
};
|
||||
}
|
||||
|
||||
public stop() {
|
||||
public async stop() {
|
||||
if (this.kibanaDiscoveryService?.isStarted()) {
|
||||
this.kibanaDiscoveryService.deleteCurrentNode().catch(() => {});
|
||||
try {
|
||||
await this.kibanaDiscoveryService.deleteCurrentNode();
|
||||
} catch (e) {
|
||||
this.logger.error(`Deleting current node has failed. error: ${e.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue