Skip to content

Commit 4a7375f

Browse files
committed
test_runner: dequeue concurrently
1 parent 641af8e commit 4a7375f

9 files changed

Lines changed: 108 additions & 27 deletions

File tree

lib/internal/test_runner/test.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,11 @@ class Test extends AsyncResource {
366366
ArrayPrototypePush(this.pendingSubtests, deferred);
367367
}
368368

369-
async processPendingSubtests() {
369+
processPendingSubtests() {
370370
while (this.pendingSubtests.length > 0 && this.hasConcurrency()) {
371371
const deferred = ArrayPrototypeShift(this.pendingSubtests);
372372
const test = deferred.test;
373-
this.reporter.dequeue(test.nesting, test.loc, test.name);
374-
await test.run();
375-
deferred.resolve();
373+
PromisePrototypeThen(test.dequeue(), deferred.resolve);
376374
}
377375
}
378376

@@ -525,6 +523,12 @@ class Test extends AsyncResource {
525523
ArrayPrototypePush(this.diagnostics, message);
526524
}
527525

526+
dequeue() {
527+
this.reporter.dequeue(this.nesting, this.loc, this.name);
528+
this.parent.activeSubtests++;
529+
return this.run();
530+
}
531+
528532
start() {
529533
// If there is enough available concurrency to run the test now, then do
530534
// it. Otherwise, return a Promise to the caller and mark the test as
@@ -537,9 +541,7 @@ class Test extends AsyncResource {
537541
this.parent.addPendingSubtest(deferred);
538542
return deferred.promise;
539543
}
540-
541-
this.reporter.dequeue(this.nesting, this.loc, this.name);
542-
return this.run();
544+
return this.dequeue();
543545
}
544546

545547
[kShouldAbort]() {
@@ -575,9 +577,6 @@ class Test extends AsyncResource {
575577
}
576578

577579
async run() {
578-
if (this.parent !== null) {
579-
this.parent.activeSubtests++;
580-
}
581580
this.startTime = hrtime();
582581

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

926925
let stopPromise;
927926
try {
928-
this.parent.activeSubtests++;
929927
await this.buildSuite;
930928
this.startTime = hrtime();
931929

test/fixtures/test-runner/output/default_output.snapshot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*[39m
99
*[39m
1010
*[39m
11+
*[39m
1112

1213
[90m﹣ should skip [90m(*ms)[39m # SKIP[39m
1314
▶ parent
@@ -18,6 +19,7 @@
1819
*[39m
1920
*[39m
2021
*[39m
22+
*[39m
2123

2224
[31m✖ should pass but parent fail [90m(*ms)[39m[39m
2325
[32m'test did not finish before its parent and was cancelled'[39m
@@ -45,6 +47,7 @@
4547
*[39m
4648
*[39m
4749
*[39m
50+
*[39m
4851

4952
*
5053
[31m✖ should fail [90m(*ms)[39m[39m
@@ -54,6 +57,7 @@
5457
*[39m
5558
*[39m
5659
*[39m
60+
*[39m
5761

5862
*
5963
[31m✖ should pass but parent fail [90m(*ms)[39m[39m

test/fixtures/test-runner/output/describe_it.snapshot

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ not ok 3 - sync todo # TODO
2525
*
2626
*
2727
*
28+
*
2829
...
2930
# Subtest: sync todo with message
3031
not ok 4 - sync todo with message # TODO this is a failing todo
@@ -42,6 +43,7 @@ not ok 4 - sync todo with message # TODO this is a failing todo
4243
*
4344
*
4445
*
46+
*
4547
...
4648
# Subtest: sync skip pass
4749
ok 5 - sync skip pass # SKIP
@@ -74,6 +76,7 @@ not ok 8 - sync throw fail
7476
*
7577
*
7678
*
79+
*
7780
...
7881
# Subtest: async skip pass
7982
ok 9 - async skip pass # SKIP
@@ -106,6 +109,7 @@ not ok 12 - async throw fail
106109
*
107110
*
108111
*
112+
*
109113
...
110114
# Subtest: async skip fail
111115
not ok 13 - async skip fail # SKIP
@@ -140,6 +144,7 @@ not ok 14 - async assertion fail
140144
*
141145
*
142146
*
147+
*
143148
...
144149
# Subtest: resolve pass
145150
ok 15 - resolve pass
@@ -162,6 +167,7 @@ not ok 16 - reject fail
162167
*
163168
*
164169
*
170+
*
165171
...
166172
# Subtest: unhandled rejection - passes but warns
167173
ok 17 - unhandled rejection - passes but warns
@@ -204,10 +210,10 @@ ok 21 - immediate resolve pass
204210
*
205211
*
206212
*
213+
*
207214
new Promise (<anonymous>)
208215
*
209216
*
210-
Array.map (<anonymous>)
211217
...
212218
# Subtest: mixing describe/it and test should work
213219
ok 2 - mixing describe/it and test should work
@@ -292,6 +298,7 @@ not ok 28 - sync skip option is false fail
292298
*
293299
*
294300
*
301+
*
295302
...
296303
# Subtest: <anonymous>
297304
ok 29 - <anonymous>
@@ -390,6 +397,7 @@ not ok 43 - callback throw
390397
*
391398
*
392399
*
400+
*
393401
...
394402
# Subtest: callback called twice
395403
not ok 44 - callback called twice
@@ -474,10 +482,10 @@ not ok 50 - custom inspect symbol that throws fail
474482
*
475483
*
476484
*
485+
*
477486
new Promise (<anonymous>)
478487
*
479488
*
480-
Array.map (<anonymous>)
481489
...
482490
# Subtest: sync throw fails at second
483491
not ok 2 - sync throw fails at second
@@ -497,7 +505,7 @@ not ok 50 - custom inspect symbol that throws fail
497505
*
498506
*
499507
*
500-
async Promise.all (index 0)
508+
*
501509
...
502510
1..2
503511
not ok 51 - subtest sync throw fails
@@ -591,6 +599,8 @@ not ok 53 - describe async throw fails
591599
failureType: 'testTimeoutFailure'
592600
error: 'test timed out after 5ms'
593601
code: 'ERR_TEST_FAILURE'
602+
stack: |-
603+
async Promise.all (index 1)
594604
...
595605
# Subtest: large timeout async test is ok
596606
ok 3 - large timeout async test is ok

test/fixtures/test-runner/output/hooks.snapshot

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ not ok 3 - after throws
140140
*
141141
*
142142
*
143+
async Promise.all (index 1)
144+
*
143145
*
144146
...
145147
1..2
@@ -190,6 +192,7 @@ not ok 4 - beforeEach throws
190192
*
191193
*
192194
*
195+
async Promise.all (index 1)
193196
*
194197
...
195198
1..2
@@ -218,10 +221,10 @@ not ok 5 - afterEach throws
218221
*
219222
*
220223
*
224+
*
221225
new Promise (<anonymous>)
222226
*
223227
*
224-
Array.map (<anonymous>)
225228
...
226229
# Subtest: 2
227230
ok 2 - 2
@@ -254,10 +257,10 @@ not ok 6 - afterEach when test fails
254257
*
255258
*
256259
*
260+
*
257261
new Promise (<anonymous>)
258262
*
259263
*
260-
Array.map (<anonymous>)
261264
...
262265
# Subtest: 2
263266
not ok 2 - 2
@@ -276,6 +279,7 @@ not ok 6 - afterEach when test fails
276279
*
277280
*
278281
*
282+
async Promise.all (index 1)
279283
*
280284
...
281285
1..2
@@ -489,6 +493,7 @@ not ok 11 - t.afterEach throws
489493
*
490494
*
491495
*
496+
*
492497
...
493498
# Subtest: 2
494499
ok 2 - 2
@@ -523,6 +528,7 @@ not ok 12 - afterEach when test fails
523528
*
524529
*
525530
*
531+
*
526532
...
527533
# Subtest: 2
528534
not ok 2 - 2

test/fixtures/test-runner/output/junit_reporter.snapshot

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
*
1919
*
2020
*
21-
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
21+
*
22+
at async startSubtest (node:internal/test_runner/harness:208:3),
2223
code: 'ERR_TEST_FAILURE'
2324
}
2425
</failure>
@@ -35,7 +36,8 @@
3536
*
3637
*
3738
*
38-
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
39+
*
40+
at async startSubtest (node:internal/test_runner/harness:208:3),
3941
code: 'ERR_TEST_FAILURE'
4042
}
4143
</failure>
@@ -59,7 +61,8 @@
5961
*
6062
*
6163
*
62-
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
64+
*
65+
at async startSubtest (node:internal/test_runner/harness:208:3),
6366
code: 'ERR_TEST_FAILURE'
6467
}
6568
</failure>
@@ -79,7 +82,8 @@
7982
*
8083
*
8184
*
82-
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
85+
*
86+
at async startSubtest (node:internal/test_runner/harness:208:3),
8387
code: 'ERR_TEST_FAILURE'
8488
}
8589
</failure>
@@ -96,7 +100,8 @@
96100
*
97101
*
98102
*
99-
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
103+
*
104+
at async startSubtest (node:internal/test_runner/harness:208:3),
100105
code: 'ERR_TEST_FAILURE'
101106
}
102107
</failure>
@@ -118,6 +123,7 @@ true !== false
118123
*
119124
*
120125
*
126+
*
121127
* {
122128
generatedMessage: true,
123129
code: 'ERR_ASSERTION',
@@ -141,7 +147,8 @@ true !== false
141147
*
142148
*
143149
*
144-
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
150+
*
151+
at async startSubtest (node:internal/test_runner/harness:208:3),
145152
code: 'ERR_TEST_FAILURE'
146153
}
147154
</failure>
@@ -167,7 +174,7 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fail
167174
*
168175
*
169176
*
170-
at Test.postRun (node:internal/test_runner/test:715:19),
177+
at Test.dequeue (node:internal/test_runner/test:529:17),
171178
code: 'ERR_TEST_FAILURE'
172179
}
173180
</failure>
@@ -213,7 +220,8 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fail
213220
*
214221
*
215222
*
216-
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
223+
*
224+
at async startSubtest (node:internal/test_runner/harness:208:3),
217225
code: 'ERR_TEST_FAILURE'
218226
}
219227
</failure>
@@ -263,7 +271,8 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fail
263271
*
264272
*
265273
*
266-
at async Test.processPendingSubtests (node:internal/test_runner/test:374:7),
274+
*
275+
at async startSubtest (node:internal/test_runner/harness:208:3),
267276
code: 'ERR_TEST_FAILURE'
268277
}
269278
</failure>
@@ -350,7 +359,7 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at first
350359
*
351360
*
352361
*
353-
at Test.postRun (node:internal/test_runner/test:715:19),
362+
at Test.dequeue (node:internal/test_runner/test:529:17),
354363
code: 'ERR_TEST_FAILURE'
355364
}
356365
</failure>
@@ -370,7 +379,7 @@ Error [ERR_TEST_FAILURE]: thrown from subtest sync throw fails at second
370379
*
371380
*
372381
*
373-
at async Test.run (node:internal/test_runner/test:632:9),
382+
at process.processImmediate (node:internal/timers:449:9),
374383
code: 'ERR_TEST_FAILURE'
375384
}
376385
</failure>

0 commit comments

Comments
 (0)