Skip to content

Commit 0a81cfc

Browse files
MoLowaduh95
authored andcommitted
fix: fix it concurrency
PR-URL: nodejs/node#43757 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Jacob Smith <[email protected]> (cherry picked from commit a3766bc8a84bcd375372a0a5c8c9174dadb6817d)
1 parent 5b6851f commit 0a81cfc

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

lib/internal/per_context/primordials.js

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ exports.PromiseResolve = val => Promise.resolve(val)
3333
exports.PromiseRace = val => Promise.race(val)
3434
exports.SafeArrayIterator = class ArrayIterator {constructor (array) { this.array = array }[Symbol.iterator] () { return this.array.values() }}
3535
exports.SafeMap = Map
36+
exports.SafePromiseAll = (array, mapFn) => Promise.all(array.map(mapFn))
3637
exports.SafeSet = Set
3738
exports.SafeWeakMap = WeakMap
3839
exports.StringPrototypeMatch = (str, reg) => str.match(reg)

lib/internal/test_runner/test.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44

55
const {
66
ArrayPrototypePush,
7-
ArrayPrototypeReduce,
87
ArrayPrototypeShift,
98
ArrayPrototypeUnshift,
109
FunctionPrototype,
1110
Number,
12-
PromiseResolve,
1311
ReflectApply,
1412
SafeMap,
15-
PromiseRace
13+
PromiseRace,
14+
SafePromiseAll
1615
} = require('#internal/per_context/primordials')
1716
const { AsyncResource } = require('async_hooks')
1817
const {
@@ -510,10 +509,7 @@ class Suite extends Test {
510509
this.parent.activeSubtests++
511510
this.startTime = hrtime()
512511
const subtests = this.skipped || this.error ? [] : this.subtests
513-
await testTimeout(ArrayPrototypeReduce(subtests, async (prev, subtest) => {
514-
await prev
515-
await subtest.run()
516-
}, PromiseResolve()), this.timeout)
512+
await SafePromiseAll(subtests, (subtests) => subtests.start())
517513
this.pass()
518514
this.postRun()
519515
}

test/message/test_runner_desctibe_it.out

+13
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ ok 20 - immediate resolve pass
188188
*
189189
*
190190
*
191+
*
192+
*
193+
*
194+
*
191195
...
192196
1..1
193197
not ok 21 - subtest sync throw fail
@@ -476,6 +480,9 @@ not ok 53 - custom inspect symbol that throws fail
476480
*
477481
*
478482
*
483+
*
484+
*
485+
*
479486
...
480487
# Subtest: sync throw fails at second
481488
not ok 2 - sync throw fails at second
@@ -491,6 +498,10 @@ not ok 53 - custom inspect symbol that throws fail
491498
*
492499
*
493500
*
501+
*
502+
*
503+
*
504+
*
494505
...
495506
1..2
496507
not ok 54 - subtest sync throw fails
@@ -565,6 +576,8 @@ not ok 56 - describe async throw fails
565576
failureType: 'testTimeoutFailure'
566577
error: 'test timed out after 5ms'
567578
code: 'ERR_TEST_FAILURE'
579+
stack: |-
580+
*
568581
...
569582
# Subtest: timed out callback test
570583
not ok 2 - timed out callback test

0 commit comments

Comments
 (0)