Skip to content

Commit

Permalink
Throw an exception when timeout too large.
Browse files Browse the repository at this point in the history
closes #1644
  • Loading branch information
callumacrae committed Apr 13, 2015
1 parent 17cec5b commit 4553d82
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Runnable.prototype.__proto__ = EventEmitter.prototype;
Runnable.prototype.timeout = function(ms){
if (0 == arguments.length) return this._timeout;
if (ms === 0) this._enableTimeouts = false;
if (ms > Math.pow(2, 31)) throw new RangeError('Interval too large, must be less than 2^31');
if ('string' == typeof ms) ms = milliseconds(ms);
debug('timeout %d', ms);
this._timeout = ms;
Expand Down
7 changes: 7 additions & 0 deletions test/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ describe('Runnable(title, fn)', function(){
})
})

describe('#timeout(ms) when ms>2^31', function(){
it('should throw an error', function () {
var run = new Runnable;
run.timeout.bind(run, 1e10).should.throw(/Interval too large/);
});
});

describe('#enableTimeouts(enabled)', function(){
it('should set enabled', function(){
var run = new Runnable;
Expand Down

0 comments on commit 4553d82

Please sign in to comment.