-
Notifications
You must be signed in to change notification settings - Fork 776
Extract tests out of queue into its own testQueue #1260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
a51ab3a
a088aa8
1f3e0ea
4e3f8b8
bf73554
a02b7a4
0fec182
c2000f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,7 @@ import config from "./config"; | |
import { | ||
defined, | ||
generateHash, | ||
now, | ||
objectType | ||
now | ||
} from "./utilities"; | ||
import { | ||
runLoggingCallbacks | ||
|
@@ -23,67 +22,83 @@ let priorityCount = 0; | |
let unitSampler; | ||
|
||
/** | ||
* Advances the ProcessingQueue to the next item if it is ready. | ||
* @param {Boolean} last | ||
* Advances the taskQueue to the next task. If the taskQueue is empty, | ||
* process the testQueue | ||
*/ | ||
function advance() { | ||
advanceTaskQueue(); | ||
|
||
if ( !config.queue.length ) { | ||
advanceTestQueue(); | ||
} | ||
} | ||
|
||
/** | ||
* Advances the taskQueue to the next task if it is ready and not empty. | ||
*/ | ||
function advanceTaskQueue() { | ||
const start = now(); | ||
config.depth = ( config.depth || 0 ) + 1; | ||
|
||
while ( config.queue.length && !config.blocking ) { | ||
const elapsedTime = now() - start; | ||
|
||
if ( !defined.setTimeout || config.updateRate <= 0 || elapsedTime < config.updateRate ) { | ||
if ( priorityCount > 0 ) { | ||
priorityCount--; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we need to reintroduce this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a TODO for that. |
||
} | ||
|
||
config.queue.shift()(); | ||
const task = config.queue.shift(); | ||
task(); | ||
} else { | ||
setTimeout( advance ); | ||
break; | ||
} | ||
} | ||
|
||
config.depth--; | ||
} | ||
|
||
if ( !config.blocking && !config.queue.length && config.depth === 0 ) { | ||
/** | ||
* Advance the testQueue to the next test to process. Call done() if testQueue completes. | ||
*/ | ||
function advanceTestQueue() { | ||
if ( !config.blocking && !config.testQueue.length && config.depth === 0 ) { | ||
done(); | ||
return; | ||
} | ||
} | ||
|
||
function addToQueueImmediate( callback ) { | ||
if ( objectType( callback ) === "array" ) { | ||
while ( callback.length ) { | ||
addToQueueImmediate( callback.pop() ); | ||
} | ||
const testTasks = config.testQueue.shift(); | ||
addToTaskQueue( testTasks() ); | ||
advance(); | ||
} | ||
|
||
return; | ||
/** | ||
* Enqueue the tasks for a test into the task queue. | ||
* @param {Array} tasksArray | ||
*/ | ||
function addToTaskQueue( tasksArray ) { | ||
for ( let i = 0; i < tasksArray.length; i++ ) { | ||
const taskItem = tasksArray[ i ]; | ||
config.queue.push( taskItem ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this whole function can be simplified to: config.queue.push(...tasksArray) What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it certainly can. Will update that. |
||
} | ||
|
||
config.queue.unshift( callback ); | ||
priorityCount++; | ||
} | ||
|
||
/** | ||
* Adds a function to the ProcessingQueue for execution. | ||
* @param {Function|Array} callback | ||
* @param {Boolean} priority | ||
* Adds a tests to the TestQueue for execution. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Should be singular, |
||
* @param {Array} testTasksArray | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could be wrong, but isn't this always going to be a function now? We pass the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct! I renamed this to |
||
* @param {Boolean} prioritize | ||
* @param {String} seed | ||
*/ | ||
function addToQueue( callback, prioritize, seed ) { | ||
function addToTestQueue( testTasksArray, prioritize, seed ) { | ||
if ( prioritize ) { | ||
config.queue.splice( priorityCount++, 0, callback ); | ||
config.testQueue.splice( priorityCount++, 0, testTasksArray ); | ||
} else if ( seed ) { | ||
if ( !unitSampler ) { | ||
unitSampler = unitSamplerGenerator( seed ); | ||
} | ||
|
||
// Insert into a random position after all prioritized items | ||
const index = Math.floor( unitSampler() * ( config.queue.length - priorityCount + 1 ) ); | ||
config.queue.splice( priorityCount + index, 0, callback ); | ||
const index = Math.floor( unitSampler() * ( config.testQueue.length - priorityCount + 1 ) ); | ||
config.testQueue.splice( priorityCount + index, 0, testTasksArray ); | ||
} else { | ||
config.queue.push( callback ); | ||
config.testQueue.push( testTasksArray ); | ||
} | ||
} | ||
|
||
|
@@ -143,8 +158,7 @@ function done() { | |
|
||
const ProcessingQueue = { | ||
finished: false, | ||
add: addToQueue, | ||
addImmediate: addToQueueImmediate, | ||
add: addToTestQueue, | ||
advance | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this code unneeded? What was its original purpose? Can you explain why we don't need it now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the original code, priorityCount's main purpose is to prioritize tests that was flagged to be executed first. The priorityCount was also incremented/decremented in
advance()
originally because if a tests needed to be inserted to the queue, it will be inserted after the tasks(which gets added to front of the queue) and after the already prioritized tests.This is not necessary anymore since the task is in it's own queue, so we do not need to deal with the priortyCount when dealing with the tasks. (Only needed for the testQueue in the new implementation)