From b016b028f6f2e4006130edcaac9303f73c89d11c Mon Sep 17 00:00:00 2001 From: John Bender Date: Sun, 26 Jun 2011 19:58:29 -0700 Subject: [PATCH] corrections in suite timeout code with a clearTimer addition --- tests/unit/index.php | 4 +++- tests/unit/runner.js | 29 ++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/tests/unit/index.php b/tests/unit/index.php index e390c2fe..afef9eb8 100644 --- a/tests/unit/index.php +++ b/tests/unit/index.php @@ -10,7 +10,9 @@
- diff --git a/tests/unit/runner.js b/tests/unit/runner.js index f39430a6..c49e9984 100644 --- a/tests/unit/runner.js +++ b/tests/unit/runner.js @@ -7,22 +7,30 @@ $.each(testDirectories, function(i, dir){ asyncTest( dir, function(){ - // give each test a maximum of two minutes to finish + var nextCheck = null; + + // establish a timeout for a given suite in case of async tests hanging var testTimeout = setTimeout( function(){ + // prevent any schedule checks for completion + clearTimeout(nextCheck); start(); - }, 2 * 60 * 1000 ); + }, 2 * 60 * 1000 ), - expect( 1 ); - updateFrame( dir ); + // setup the next state check and record the timer id for removal + scheduleCheck = function(){ + nextCheck = setTimeout( check, 2000 ); + }, + + // check the iframe for success or failure and respond accordingly + check = function(){ - function check(){ // check for the frames jquery object each time var framejQuery = window.frames["testFrame"].jQuery; // if the iframe hasn't loaded (ie loaded jQuery) check back again shortly if( !framejQuery ){ + scheduleCheck(); return; - setTimeout( arguments.callee, 2000 ); } // grab the result of the iframe test suite @@ -34,11 +42,14 @@ clearTimeout(testTimeout); start(); } else { - setTimeout( arguments.callee, 2000 ); + scheduleCheck(); } - } + }; - setTimeout( check, 2000 ); + + expect( 1 ); + updateFrame( dir ); + scheduleCheck(); }); }); })();