From 62818fa044914eb79a4845de12e364a1aff09c09 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Mon, 13 Apr 2015 18:14:09 +0100 Subject: [PATCH] Throw an exception when timeout too large. closes #1644 --- lib/runnable.js | 3 ++- test/runnable.js | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/runnable.js b/lib/runnable.js index c7d210d5b2..7ccb4e3ffc 100644 --- a/lib/runnable.js +++ b/lib/runnable.js @@ -74,7 +74,8 @@ Runnable.prototype.timeout = function(ms) { if (!arguments.length) { return this._timeout; } - if (ms === 0) { + // see #1652 for reasoning + if (ms === 0 || ms > Math.pow(2, 31)) { this._enableTimeouts = false; } if (typeof ms === 'string') { diff --git a/test/runnable.js b/test/runnable.js index a3d88adda2..ba1ea48f55 100644 --- a/test/runnable.js +++ b/test/runnable.js @@ -41,6 +41,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;