[Monitoring] Await promise properly (#29001) (#29504)

* Await this promise

* Add one additional log message and a test around that
This commit is contained in:
Chris Roberson 2019-01-29 10:12:25 -05:00 committed by GitHub
parent 8ba8772f92
commit 67dc8c080c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View file

@ -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',

View file

@ -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`);