diff --git a/x-pack/plugins/monitoring/server/kibana_monitoring/__tests__/bulk_uploader.js b/x-pack/plugins/monitoring/server/kibana_monitoring/__tests__/bulk_uploader.js index fe17f205c65b9..2c6c52ed05ca6 100644 --- a/x-pack/plugins/monitoring/server/kibana_monitoring/__tests__/bulk_uploader.js +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/__tests__/bulk_uploader.js @@ -39,7 +39,9 @@ describe('BulkUploader', () => { getCluster: () => ({ createClient: () => ({ monitoring: { - bulk: sinon.spy(), + bulk: function () { + return new Promise(resolve => setTimeout(resolve, CHECK_DELAY + 1)); + } }, }), callWithInternalUser: sinon.spy(), // this tests internal collection and bulk upload, not HTTP API @@ -106,7 +108,9 @@ describe('BulkUploader', () => { uploader.stop(); const loggingCalls = server.log.getCalls(); - expect(loggingCalls.length).to.be.greaterThan(2); // should be 3-5: start, fetch, upload, fetch, upload + // If we are properly awaiting the bulk upload call, we shouldn't see + // the last 2 logs as the call takes longer than this timeout (see the above mock) + expect(loggingCalls.length).to.be(4); expect(loggingCalls[0].args).to.eql([ ['info', 'monitoring-ui', 'kibana-monitoring'], 'Starting monitoring stats collection', diff --git a/x-pack/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js b/x-pack/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js index 6eeab649f0e0d..5d7c2f3f5d8b7 100644 --- a/x-pack/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js +++ b/x-pack/plugins/monitoring/server/kibana_monitoring/bulk_uploader.js @@ -103,7 +103,8 @@ export class BulkUploader { if (payload) { try { this._log.debug(`Uploading bulk stats payload to the local cluster`); - this._onPayload(payload); + await this._onPayload(payload); + this._log.debug(`Uploaded bulk stats payload to the local cluster`); } catch (err) { this._log.warn(err.stack); this._log.warn(`Unable to bulk upload the stats payload to the local cluster`);