From 434e8c3f12b2df2a39108ceb16044c8f5c72e4cb Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Fri, 8 Jul 2016 01:00:21 -0400 Subject: [PATCH] Core: Better isolate async abstractions --- src/assert.js | 9 +++------ src/core.js | 27 ++++++++++++++++++--------- src/test.js | 4 ---- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/assert.js b/src/assert.js index 833f0d46c..3045af2a9 100644 --- a/src/assert.js +++ b/src/assert.js @@ -15,8 +15,7 @@ QUnit.assert = Assert.prototype = { } }, - // Increment this Test's semaphore counter, then return a function that - // decrements that counter a maximum of once. + // Put a hold on processing and return a function that will release it a maximum of once. async: function( count ) { var test = this.test, popped = false, @@ -26,9 +25,8 @@ QUnit.assert = Assert.prototype = { acceptCallCount = 1; } - test.semaphore += 1; test.usedAsync = true; - pauseProcessing( test ); + internalStop( test ); return function done() { @@ -42,9 +40,8 @@ QUnit.assert = Assert.prototype = { return; } - test.semaphore -= 1; popped = true; - resumeProcessing( test ); + internalStart( test ); }; }, diff --git a/src/core.js b/src/core.js index e736f2f03..e6d1a1a78 100644 --- a/src/core.js +++ b/src/core.js @@ -111,7 +111,7 @@ extend( QUnit, { ); } - resumeProcessing(); + scheduleBegin(); }, config: config, @@ -138,7 +138,7 @@ extend( QUnit, { config.blocking = false; if ( config.autostart ) { - resumeProcessing(); + scheduleBegin(); } }, @@ -150,6 +150,20 @@ extend( QUnit, { registerLoggingCallbacks( QUnit ); +function scheduleBegin() { + + runStarted = true; + + // Add a slight delay to allow definition of more modules and tests. + if ( defined.setTimeout ) { + setTimeout( function() { + begin(); + }, 13 ); + } else { + begin(); + } +} + function begin() { var i, l, modulesLog = []; @@ -225,24 +239,19 @@ function pauseProcessing( test ) { } function resumeProcessing( test ) { - runStarted = true; // A slight delay to allow this iteration of the event loop to finish (more assertions, etc.) if ( defined.setTimeout ) { setTimeout( function() { - var current = test || config.current; - if ( current && ( current.semaphore > 0 || current.resumed ) ) { + if ( test.semaphore > 0 || test.resumed ) { return; } + test.resumed = true; if ( config.timeout ) { clearTimeout( config.timeout ); } - if ( current ) { - current.resumed = true; - } - begin(); }, 13 ); } else { diff --git a/src/test.js b/src/test.js index 3df4ec3c9..365b28da3 100644 --- a/src/test.js +++ b/src/test.js @@ -627,16 +627,12 @@ function only( testName, callback ) { } function internalStop( test ) { - - // If a test is running, adjust its semaphore test.semaphore += 1; pauseProcessing( test ); } function internalStart( test ) { - - // If a test is running, adjust its semaphore test.semaphore -= 1; // If semaphore is non-numeric, throw error