Skip to content

Commit

Permalink
Merge pull request serverless#5503 from serverless/fix-5497
Browse files Browse the repository at this point in the history
Convert logging to return a promise so that serverless#5349 no longer causes serverless#5497
  • Loading branch information
dschep authored Nov 19, 2018
2 parents 3033540 + de67fa5 commit a877808
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/plugins/aws/logs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class AwsLogs {
showLogs(logStreamNames) {
if (!logStreamNames || !logStreamNames.length) {
if (this.options.tail) {
return setTimeout((() => this.getLogStreams()
.then(nextLogStreamNames => this.showLogs(nextLogStreamNames))),
this.options.interval);
return BbPromise.delay(this.options.interval)
.then(this.getLogStreams.bind(this))
.then(this.showLogs.bind(this));
}
}

Expand Down Expand Up @@ -116,9 +116,9 @@ class AwsLogs {
this.options.startTime = _.last(results.events).timestamp + 1;
}

return setTimeout((() => this.getLogStreams()
.then(nextLogStreamNames => this.showLogs(nextLogStreamNames))),
this.options.interval);
return BbPromise.delay(this.options.interval)
.then(this.getLogStreams.bind(this))
.then(this.showLogs.bind(this));
}

return BbPromise.resolve();
Expand Down
4 changes: 4 additions & 0 deletions lib/plugins/aws/logs/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const bluebird = require('bluebird');
const expect = require('chai').expect;
const sinon = require('sinon');
const AwsProvider = require('../provider/awsProvider');
Expand Down Expand Up @@ -340,8 +341,10 @@ describe('AwsLogs', () => {
logGroupName: awsLogs.provider.naming.getLogGroupName('new-service-dev-first'),
tail: true,
};
const bbPromiseDelay = sinon.stub(bluebird, 'delay').rejects();

return awsLogs.showLogs(logStreamNamesMock)
.catch(() => true) // Promise.delay has to reject or it'll loop forever
.then(() => {
expect(filterLogEventsStub.calledOnce).to.be.equal(true);
expect(filterLogEventsStub.calledWithExactly(
Expand All @@ -356,6 +359,7 @@ describe('AwsLogs', () => {
)).to.be.equal(true);

awsLogs.provider.request.restore();
bbPromiseDelay.restore();
});
});
});
Expand Down

0 comments on commit a877808

Please sign in to comment.