Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test_runner: dequeue concurrently
  • Loading branch information
MoLow committed Sep 23, 2023
commit 4a7375ffe5ae572ce6ca6f24253219d14a36399f
20 changes: 9 additions & 11 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,11 @@ class Test extends AsyncResource {
ArrayPrototypePush(this.pendingSubtests, deferred);
}

async processPendingSubtests() {
processPendingSubtests() {
while (this.pendingSubtests.length > 0 && this.hasConcurrency()) {
const deferred = ArrayPrototypeShift(this.pendingSubtests);
const test = deferred.test;
this.reporter.dequeue(test.nesting, test.loc, test.name);
await test.run();
deferred.resolve();
PromisePrototypeThen(test.dequeue(), deferred.resolve);
}
}

Expand Down Expand Up @@ -525,6 +523,12 @@ class Test extends AsyncResource {
ArrayPrototypePush(this.diagnostics, message);
}

dequeue() {
this.reporter.dequeue(this.nesting, this.loc, this.name);
this.parent.activeSubtests++;
return this.run();
}

start() {
// If there is enough available concurrency to run the test now, then do
// it. Otherwise, return a Promise to the caller and mark the test as
Expand All @@ -537,9 +541,7 @@ class Test extends AsyncResource {
this.parent.addPendingSubtest(deferred);
return deferred.promise;
}

this.reporter.dequeue(this.nesting, this.loc, this.name);
return this.run();
return this.dequeue();
}

[kShouldAbort]() {
Expand Down Expand Up @@ -575,9 +577,6 @@ class Test extends AsyncResource {
}

async run() {
if (this.parent !== null) {
this.parent.activeSubtests++;
}
this.startTime = hrtime();

if (this[kShouldAbort]()) {
Expand Down Expand Up @@ -925,7 +924,6 @@ class Suite extends Test {

let stopPromise;
try {
this.parent.activeSubtests++;
await this.buildSuite;
this.startTime = hrtime();

Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/test-runner/output/default_output.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*[39m
*[39m
*[39m
*[39m

[90m﹣ should skip [90m(*ms)[39m # SKIP[39m
▶ parent
Expand All @@ -18,6 +19,7 @@
*[39m
*[39m
*[39m
*[39m

[31m✖ should pass but parent fail [90m(*ms)[39m[39m
[32m'test did not finish before its parent and was cancelled'[39m
Expand Down Expand Up @@ -45,6 +47,7 @@
*[39m
*[39m
*[39m
*[39m

*
[31m✖ should fail [90m(*ms)[39m[39m
Expand All @@ -54,6 +57,7 @@
*[39m
*[39m
*[39m
*[39m

*
[31m✖ should pass but parent fail [90m(*ms)[39m[39m
Expand Down
16 changes: 13 additions & 3 deletions test/fixtures/test-runner/output/describe_it.snapshot
Comment thread
MoLow marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ not ok 3 - sync todo # TODO
*
*
*
*
...
# Subtest: sync todo with message
not ok 4 - sync todo with message # TODO this is a failing todo
Expand All @@ -42,6 +43,7 @@ not ok 4 - sync todo with message # TODO this is a failing todo
*
*
*
*
...
# Subtest: sync skip pass
ok 5 - sync skip pass # SKIP
Expand Down Expand Up @@ -74,6 +76,7 @@ not ok 8 - sync throw fail
*
*
*
*
...
# Subtest: async skip pass
ok 9 - async skip pass # SKIP
Expand Down Expand Up @@ -106,6 +109,7 @@ not ok 12 - async throw fail
*
*
*
*
...
# Subtest: async skip fail
not ok 13 - async skip fail # SKIP
Expand Down Expand Up @@ -140,6 +144,7 @@ not ok 14 - async assertion fail
*
*
*
*
...
# Subtest: resolve pass
ok 15 - resolve pass
Expand All @@ -162,6 +167,7 @@ not ok 16 - reject fail
*
*
*
*
...
# Subtest: unhandled rejection - passes but warns
ok 17 - unhandled rejection - passes but warns
Expand Down Expand Up @@ -204,10 +210,10 @@ ok 21 - immediate resolve pass
*
*
*
*
new Promise (<anonymous>)
*
*
Array.map (<anonymous>)
...
# Subtest: mixing describe/it and test should work
ok 2 - mixing describe/it and test should work
Expand Down Expand Up @@ -292,6 +298,7 @@ not ok 28 - sync skip option is false fail
*
*
*
*
...
# Subtest: <anonymous>
ok 29 - <anonymous>
Expand Down Expand Up @@ -390,6 +397,7 @@ not ok 43 - callback throw
*
*
*
*
...
# Subtest: callback called twice
not ok 44 - callback called twice
Expand Down Expand Up @@ -474,10 +482,10 @@ not ok 50 - custom inspect symbol that throws fail
*
*
*
*
new Promise (<anonymous>)
*
*
Array.map (<anonymous>)
...
# Subtest: sync throw fails at second
not ok 2 - sync throw fails at second
Expand All @@ -497,7 +505,7 @@ not ok 50 - custom inspect symbol that throws fail
*
*
*
async Promise.all (index 0)
*
...
1..2
not ok 51 - subtest sync throw fails
Expand Down Expand Up @@ -591,6 +599,8 @@ not ok 53 - describe async throw fails
failureType: 'testTimeoutFailure'
error: 'test timed out after 5ms'
code: 'ERR_TEST_FAILURE'
stack: |-
async Promise.all (index 1)
...
# Subtest: large timeout async test is ok
ok 3 - large timeout async test is ok
Expand Down
10 changes: 8 additions & 2 deletions test/fixtures/test-runner/output/hooks.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ not ok 3 - after throws
*
*
*
async Promise.all (index 1)
*
*
...
1..2
Expand Down Expand Up @@ -190,6 +192,7 @@ not ok 4 - beforeEach throws
*
*
*
async Promise.all (index 1)
*
...
1..2
Expand Down Expand Up @@ -218,10 +221,10 @@ not ok 5 - afterEach throws
*
*
*
*
new Promise (<anonymous>)
*
*
Array.map (<anonymous>)
...
# Subtest: 2
ok 2 - 2
Expand Down Expand Up @@ -254,10 +257,10 @@ not ok 6 - afterEach when test fails
*
*
*
*
new Promise (<anonymous>)
*
*
Array.map (<anonymous>)
...
# Subtest: 2
not ok 2 - 2
Expand All @@ -276,6 +279,7 @@ not ok 6 - afterEach when test fails
*
*
*
async Promise.all (index 1)
*
...
1..2
Expand Down Expand Up @@ -489,6 +493,7 @@ not ok 11 - t.afterEach throws
*
*
*
*
...
# Subtest: 2
ok 2 - 2
Expand Down Expand Up @@ -523,6 +528,7 @@ not ok 12 - afterEach when test fails
*
*
*
*
...
# Subtest: 2
not ok 2 - 2
Expand Down
31 changes: 20 additions & 11 deletions test/fixtures/test-runner/output/junit_reporter.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*
*
*
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
*
at async startSubtest (node:internal/test_runner/harness:208:3),
code: 'ERR_TEST_FAILURE'
}
</failure>
Expand All @@ -35,7 +36,8 @@
*
*
*
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
*
at async startSubtest (node:internal/test_runner/harness:208:3),
code: 'ERR_TEST_FAILURE'
}
</failure>
Expand All @@ -59,7 +61,8 @@
*
*
*
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
*
at async startSubtest (node:internal/test_runner/harness:208:3),
code: 'ERR_TEST_FAILURE'
}
</failure>
Expand All @@ -79,7 +82,8 @@
*
*
*
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
*
at async startSubtest (node:internal/test_runner/harness:208:3),
code: 'ERR_TEST_FAILURE'
}
</failure>
Expand All @@ -96,7 +100,8 @@
*
*
*
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
*
at async startSubtest (node:internal/test_runner/harness:208:3),
code: 'ERR_TEST_FAILURE'
}
</failure>
Expand All @@ -118,6 +123,7 @@ true !== false
*
*
*
*
* {
generatedMessage: true,
code: 'ERR_ASSERTION',
Expand All @@ -141,7 +147,8 @@ true !== false
*
*
*
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
*
at async startSubtest (node:internal/test_runner/harness:208:3),
code: 'ERR_TEST_FAILURE'
}
</failure>
Expand All @@ -167,7 +174,7 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fail
*
*
*
at Test.postRun (node:internal/test_runner/test:715:19),
at Test.dequeue (node:internal/test_runner/test:529:17),
code: 'ERR_TEST_FAILURE'
}
</failure>
Expand Down Expand Up @@ -213,7 +220,8 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fail
*
*
*
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
*
at async startSubtest (node:internal/test_runner/harness:208:3),
code: 'ERR_TEST_FAILURE'
}
</failure>
Expand Down Expand Up @@ -263,7 +271,8 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fail
*
*
*
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
*
at async startSubtest (node:internal/test_runner/harness:208:3),
code: 'ERR_TEST_FAILURE'
}
</failure>
Expand Down Expand Up @@ -350,7 +359,7 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at first
*
*
*
at Test.postRun (node:internal/test_runner/test:715:19),
at Test.dequeue (node:internal/test_runner/test:529:17),
code: 'ERR_TEST_FAILURE'
}
</failure>
Expand All @@ -370,7 +379,7 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at second
*
*
*
at async Test.run (node:internal/test_runner/test:632:9),
at process.processImmediate (node:internal/timers:449:9),
code: 'ERR_TEST_FAILURE'
}
</failure>
Expand Down
Loading