Skip to content

Commit

Permalink
Merge pull request #1652 from callumacrae/timeout-exception
Browse files Browse the repository at this point in the history
Throw an exception when timeout too large.
  • Loading branch information
dasilvacontin committed Apr 13, 2015
2 parents 17cec5b + ace073d commit 450ecbf
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
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('Timeout 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
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(/Timeout too large/);
});
});

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

0 comments on commit 450ecbf

Please sign in to comment.