Skip to content

Commit

Permalink
corrections in suite timeout code with a clearTimer addition
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbender committed Jun 27, 2011
1 parent 32f5b22 commit b016b02
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
4 changes: 3 additions & 1 deletion tests/unit/index.php
Expand Up @@ -10,7 +10,9 @@
<ol id="qunit-tests">
</ol>
</div>
<iframe data-src="../../tests/unit/{{testdir}}" name="testFrame" id="testFrame" width="800px" height="100%" style="float: left; border: 0px;" scrolling="no">
<!-- under normal circumstances inline styles would be a poor choice, but in this case
I think an entire link and stylesheet is a waste -->
<iframe data-src="../../tests/unit/{{testdir}}" name="testFrame" id="testFrame" width="800px" height="100%" style="float: left; border: 0px; height: 100%;" scrolling="no">
</iframe>
<link rel="stylesheet" href="../../external/qunit.css"></link>
<script src="../../js/jquery.js"></script>
Expand Down
29 changes: 20 additions & 9 deletions tests/unit/runner.js
Expand Up @@ -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
Expand All @@ -34,11 +42,14 @@
clearTimeout(testTimeout);
start();
} else {
setTimeout( arguments.callee, 2000 );
scheduleCheck();
}
}
};


setTimeout( check, 2000 );
expect( 1 );
updateFrame( dir );
scheduleCheck();
});
});
})();

0 comments on commit b016b02

Please sign in to comment.