Skip to content

Commit

Permalink
Honoring timeout for sync operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdevel authored and jxspencer committed Jun 19, 2014
1 parent fb0447e commit 6f912b8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
15 changes: 13 additions & 2 deletions Makefile
Expand Up @@ -32,7 +32,7 @@ lib-cov:

test: test-unit

test-all: test-bdd test-tdd test-qunit test-exports test-unit test-grep test-jsapi test-compilers test-sort test-glob test-requires test-reporters test-only
test-all: test-bdd test-tdd test-qunit test-exports test-unit test-grep test-jsapi test-compilers test-sort test-glob test-requires test-reporters test-only test-failing

test-jsapi:
@node test/jsapi
Expand All @@ -44,6 +44,17 @@ test-unit:
--growl \
test/*.js

test-failing:
@./bin/mocha \
--reporter $(REPORTER) \
test/acceptance/failing/timeout.js > /dev/null 2>&1 ; \
failures="$$?" ; \
if [ "$$failures" != '2' ] ; then \
echo 'test-failing:' ; \
echo " expected 2 failing tests but saw $$failures" ; \
exit 1 ; \
fi

test-compilers:
@./bin/mocha \
--reporter $(REPORTER) \
Expand Down Expand Up @@ -165,4 +176,4 @@ non-tty:
tm:
@open editors/$(TM_BUNDLE)

.PHONY: test-cov test-jsapi test-compilers watch test test-all test-bdd test-tdd test-qunit test-exports test-unit non-tty test-grep tm clean
.PHONY: test-cov test-jsapi test-compilers watch test test-all test-bdd test-tdd test-qunit test-exports test-unit non-tty test-grep test-failing tm clean
3 changes: 2 additions & 1 deletion lib/runnable.js
Expand Up @@ -160,7 +160,6 @@ Runnable.prototype.globals = function(arr){

Runnable.prototype.run = function(fn){
var self = this
, ms = this.timeout()
, start = new Date
, ctx = this.ctx
, finished
Expand All @@ -177,11 +176,13 @@ Runnable.prototype.run = function(fn){

// finished
function done(err) {
var ms = self.timeout();
if (self.timedOut) return;
if (finished) return multiple(err);
self.clearTimeout();
self.duration = new Date - start;
finished = true;
if (!err && self.duration > ms) err = new Error('timeout of ' + ms + 'ms exceeded');
fn(err);
}

Expand Down
18 changes: 18 additions & 0 deletions test/acceptance/failing/timeout.js
@@ -0,0 +1,18 @@

describe('timeout', function(){
this.timeout(20);

it('should be honored with sync suites', function(){
sleep(30);
});

it('should be honored with async suites', function(done){
sleep(30);
done();
});

function sleep(ms){
var start = Date.now();
while(start + ms > Date.now())continue;
}
});

0 comments on commit 6f912b8

Please sign in to comment.