Skip to content
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

Fix the queue tree from resolving in between the testcase. #4322

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/core/asynctree.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ class AsyncTree extends EventEmitter{
}

async done(err = null) {
if (this.currentResult instanceof Promise && !this.currentResult.settled) {
return err;
}

this.emit('asynctree:finished', this);
this.empty();
this.createRootNode();
Expand Down
4 changes: 3 additions & 1 deletion lib/core/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ class CommandQueue extends EventEmitter {
return Promise.resolve();
}

run() {
run(result) {
this.tree.currentResult = result;

if (this.tree.started) {
return this;
}
Expand Down
16 changes: 13 additions & 3 deletions lib/testsuite/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class Runnable {
}

setDoneCallback(cb) {
let originalResolve = this.deffered.resolveFn;
let originalReject = this.deffered.rejectFn;
const originalResolve = this.deffered.resolveFn;
const originalReject = this.deffered.rejectFn;
this.deffered.resolveFn = function() {};
this.deffered.rejectFn = function() {};

Expand Down Expand Up @@ -134,13 +134,22 @@ class Runnable {
const deferredFn = () => {
result
.then(res_ => {
result.settled = true;
if (this.queueInProgress()) {
// After resolution of testcase (`result` here), if there are some more
// commands left to be run in the queue, the queue will automatically resolve
// after those commands are finished running. But, if at this time, the queue
// is already done running and was not resolved earlier because the testcase
// was not yet resolved, this gives another chance for the queue to be resolved.
this.queue.scheduleTraverse();

return;
}

this.deffered.resolveFn(res_);
})
.catch(err => {
result.settled = true;
this.deffered.rejectFn(err);
});
};
Expand All @@ -152,14 +161,15 @@ class Runnable {
// without .catch() here, we can get an unhandledRejection
result
.catch(err => {
result.settled = true;
this.deffered.rejectFn(err);
});
} else {
deferredFn();
}
}

this.queue.run().then(err => {
this.queue.run(result).then(err => {
if (err) {
return this.deffered.rejectFn(err);
}
Expand Down
Loading