Extract tests out of queue into its own testQueue#1260
Extract tests out of queue into its own testQueue#1260trentmwillis merged 8 commits intoqunitjs:masterfrom
Conversation
|
Stephen Yeung seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. |
| const elapsedTime = now() - start; | ||
|
|
||
| if ( !defined.setTimeout || config.updateRate <= 0 || elapsedTime < config.updateRate ) { | ||
| if ( priorityCount > 0 ) { |
There was a problem hiding this comment.
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.
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)
src/core/processing-queue.js
Outdated
| 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.
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.
Yes, it certainly can. Will update that.
trentmwillis
left a comment
There was a problem hiding this comment.
I haven't reviewed the changes yet, but I'm curious (as it isn't clear from the PR description) as to what the goal is with this change?
We're introducing another field into QUnit.config, but I'm not clear on what the benefit of doing so is for consumers. Is there a use case you have in mind for it?
|
I don’t think the intent is really related to exposing another queue, just trying to simply the queueing logic. In the long run, having separate queues for the list of tasks for a single test and the pending tests will make it easier to add more logic around test to test advancing (e.g. so that measurements can be done to prevent memory leaks and/or identify per-test code coverage), but that is definitely not the goal of this PR itself. This PR is only about simplifying the queuing logic (having a single queue where some items are prepended and others are appended is really confusing). |
|
If you’d prefer to avoid adding a new property on QUnit.config I think we can most likely do that. @step2yeung - Can you confirm? |
|
Thanks for clarifying @rwjblue! |
|
Yeah, my concern is primarily around adding a new public property. If we can keep |
|
@trentmwillis Thanks for the feedback! I modified it such that |
rwjblue
left a comment
There was a problem hiding this comment.
This is looking really good to me, thanks for working on this cleanup @step2yeung!
@trentmwillis - Have any time for a follow-up review?
| if ( hookName === "after" && | ||
| hookOwner.unskippedTestsRun !== numberOfUnskippedTests( hookOwner ) - 1 && | ||
| config.queue.length > 2 ) { | ||
| ( config.queue.length > 0 || ProcessingQueue.taskCount() > 2 ) ) { |
There was a problem hiding this comment.
Not really related to this PR since it was pre-exixting, but this took me a little while to figure out (specifically, why is > 2 important), it may warrant an inline comment...
There was a problem hiding this comment.
Agreed...should've done that last time I refactored this code
trentmwillis
left a comment
There was a problem hiding this comment.
Thanks for working on this! Sorry for being slow to review. Overall, the implementation seems pretty good. Mainly have some suggestions around comments/clarification for future travelers.
|
|
||
| let priorityCount = 0; | ||
| let unitSampler; | ||
| const taskQueue = []; |
There was a problem hiding this comment.
It would be nice to have a comment describing what a task is within the taskQueue. Something to the effect of:
This is queue of functions that are tasks within a single test. After tests and removed from config.queue they are expanded into a set of tasks in this queue.
src/core/processing-queue.js
Outdated
| * 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.
Nit: Should be singular, test.
| if ( hookName === "after" && | ||
| hookOwner.unskippedTestsRun !== numberOfUnskippedTests( hookOwner ) - 1 && | ||
| config.queue.length > 2 ) { | ||
| ( config.queue.length > 0 || ProcessingQueue.taskCount() > 2 ) ) { |
There was a problem hiding this comment.
Agreed...should've done that last time I refactored this code
src/core/processing-queue.js
Outdated
| * @param {Function|Array} callback | ||
| * @param {Boolean} priority | ||
| * Adds a tests to the TestQueue for execution. | ||
| * @param {Array} testTasksArray |
There was a problem hiding this comment.
I could be wrong, but isn't this always going to be a function now? We pass the runTest function into here, and then later shift them off and then pass the expanded array to addToTaskQueue, right?
There was a problem hiding this comment.
Correct! I renamed this to testTasksFunc
|
|
||
| if ( !defined.setTimeout || config.updateRate <= 0 || elapsedTime < config.updateRate ) { | ||
| if ( priorityCount > 0 ) { | ||
| priorityCount--; |
There was a problem hiding this comment.
I believe we need to reintroduce this priorityCount decrement somewhere so that if a high priority test is added after the run starts, it should be placed in the right spot. I doubt we have a proper test for this, so we could always add that back with a test in a separate PR.
There was a problem hiding this comment.
Added a TODO for that.
trentmwillis
left a comment
There was a problem hiding this comment.
Looks good to me, thanks a bunch!
This PR separates the content of
Qunit.config.queuewhich contains both tests (runTest function) and its tasks(each function added to the queue by runTest) into two separate queue: queue and testQueue.Previously the queue was serving two purposes:
This PR also goes along the lines of the first comment by
platinumazurein this PR: #1124The idea of this change is to clean up and simplify the queue logic to make it easier to reason about. The change separates the processing of tests and its tasks, giving a clear indication when all the tasks of a tests are complete, and when the next test can begin.
Before:
After: