Skip to content

Commit

Permalink
[Monitoring] Await promise properly (#29001)
Browse files Browse the repository at this point in the history
* Await this promise

* Add one additional log message and a test around that
  • Loading branch information
chrisronline authored Jan 29, 2019
1 parent fc1d146 commit 5b9f2ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down

0 comments on commit 5b9f2ba

Please sign in to comment.