mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[es/healthcheck] ensure that healthcheck stops when server is stopped (#13201)
This commit is contained in:
parent
b5e13ff1d0
commit
924548864d
2 changed files with 35 additions and 2 deletions
|
@ -21,8 +21,13 @@ describe('plugins/elasticsearch', () => {
|
|||
let health;
|
||||
let plugin;
|
||||
let cluster;
|
||||
let server;
|
||||
const sandbox = sinon.sandbox.create();
|
||||
|
||||
function getTimerCount() {
|
||||
return Object.keys(sandbox.clock.timers || {}).length;
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
const COMPATIBLE_VERSION_NUMBER = '5.0.0';
|
||||
|
||||
|
@ -66,7 +71,7 @@ describe('plugins/elasticsearch', () => {
|
|||
const set = sinon.stub();
|
||||
|
||||
// Setup the server mock
|
||||
const server = {
|
||||
server = {
|
||||
log: sinon.stub(),
|
||||
info: { port: 5601 },
|
||||
config: function () { return { get, set }; },
|
||||
|
@ -77,7 +82,8 @@ describe('plugins/elasticsearch', () => {
|
|||
},
|
||||
getKibanaIndexMappingsDsl() {
|
||||
return mappings;
|
||||
}
|
||||
},
|
||||
ext: sinon.stub()
|
||||
};
|
||||
|
||||
health = healthCheck(plugin, server);
|
||||
|
@ -85,6 +91,28 @@ describe('plugins/elasticsearch', () => {
|
|||
|
||||
afterEach(() => sandbox.restore());
|
||||
|
||||
it('should stop when cluster is shutdown', () => {
|
||||
sandbox.useFakeTimers();
|
||||
|
||||
// ensure that health.start() is responsible for the timer we are observing
|
||||
expect(getTimerCount()).to.be(0);
|
||||
health.start();
|
||||
expect(getTimerCount()).to.be(1);
|
||||
|
||||
// ensure that a server extension was registered
|
||||
sinon.assert.calledOnce(server.ext);
|
||||
sinon.assert.calledWithExactly(server.ext, sinon.match.string, sinon.match.func);
|
||||
|
||||
// call the server extension
|
||||
const reply = sinon.stub();
|
||||
const [,handler] = server.ext.firstCall.args;
|
||||
handler({}, reply);
|
||||
|
||||
// ensure that the handler called reply and unregistered the time
|
||||
sinon.assert.calledOnce(reply);
|
||||
expect(getTimerCount()).to.be(0);
|
||||
});
|
||||
|
||||
it('should set the cluster green if everything is ready', function () {
|
||||
cluster.callWithInternalUser.withArgs('ping').returns(Promise.resolve());
|
||||
cluster.callWithInternalUser.withArgs('cluster.health', sinon.match.any).returns(
|
||||
|
|
|
@ -145,6 +145,11 @@ export default function (plugin, server) {
|
|||
return true;
|
||||
}
|
||||
|
||||
server.ext('onPreStop', (request, reply) => {
|
||||
stopChecking();
|
||||
reply();
|
||||
});
|
||||
|
||||
return {
|
||||
waitUntilReady: waitUntilReady,
|
||||
run: check,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue