From a7dde46c0d35592bbbeb950166b2d877b68dbf20 Mon Sep 17 00:00:00 2001 From: Priyansh Garg Date: Thu, 5 Dec 2024 16:03:37 +0530 Subject: [PATCH] Fix the queue tree from resolving in between the testcase. --- lib/core/asynctree.js | 4 ++++ lib/core/queue.js | 4 +++- lib/testsuite/runnable.js | 16 +++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/core/asynctree.js b/lib/core/asynctree.js index 926a45a17f..4c8e31bf82 100644 --- a/lib/core/asynctree.js +++ b/lib/core/asynctree.js @@ -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(); diff --git a/lib/core/queue.js b/lib/core/queue.js index 3e8b3a71bb..884d0c69cc 100644 --- a/lib/core/queue.js +++ b/lib/core/queue.js @@ -145,7 +145,9 @@ class CommandQueue extends EventEmitter { return Promise.resolve(); } - run() { + run(result) { + this.tree.currentResult = result; + if (this.tree.started) { return this; } diff --git a/lib/testsuite/runnable.js b/lib/testsuite/runnable.js index b60f43d3a8..6275a2f23e 100644 --- a/lib/testsuite/runnable.js +++ b/lib/testsuite/runnable.js @@ -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() {}; @@ -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); }); }; @@ -152,6 +161,7 @@ class Runnable { // without .catch() here, we can get an unhandledRejection result .catch(err => { + result.settled = true; this.deffered.rejectFn(err); }); } else { @@ -159,7 +169,7 @@ class Runnable { } } - this.queue.run().then(err => { + this.queue.run(result).then(err => { if (err) { return this.deffered.rejectFn(err); }