Skip to content

Commit

Permalink
fix: fix it concurrency
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
MoLow authored and aduh95 committed Jul 16, 2022
1 parent c9cba61 commit fc19407
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ exports.PromiseResolve = val => Promise.resolve(val)
exports.PromiseRace = val => Promise.race(val)
exports.SafeArrayIterator = class ArrayIterator {constructor (array) { this.array = array }[Symbol.iterator] () { return this.array.values() }}
exports.SafeMap = Map
exports.SafePromiseAll = (array, mapFn) => Promise.all(array.map(mapFn))
exports.SafeSet = Set
exports.SafeWeakMap = WeakMap
exports.StringPrototypeMatch = (str, reg) => str.match(reg)
Expand Down
10 changes: 3 additions & 7 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

const {
ArrayPrototypePush,
ArrayPrototypeReduce,
ArrayPrototypeShift,
ArrayPrototypeUnshift,
FunctionPrototype,
Number,
PromiseResolve,
ReflectApply,
SafeMap,
PromiseRace
PromiseRace,
SafePromiseAll
} = require('#internal/per_context/primordials')
const { AsyncResource } = require('async_hooks')
const {
Expand Down Expand Up @@ -510,10 +509,7 @@ class Suite extends Test {
this.parent.activeSubtests++
this.startTime = hrtime()
const subtests = this.skipped || this.error ? [] : this.subtests
await testTimeout(ArrayPrototypeReduce(subtests, async (prev, subtest) => {
await prev
await subtest.run()
}, PromiseResolve()), this.timeout)
await SafePromiseAll(subtests, (subtests) => subtests.start())
this.pass()
this.postRun()
}
Expand Down
13 changes: 13 additions & 0 deletions test/message/test_runner_desctibe_it.out
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ ok 20 - immediate resolve pass
*
*
*
*
*
*
*
...
1..1
not ok 21 - subtest sync throw fail
Expand Down Expand Up @@ -476,6 +480,9 @@ not ok 53 - custom inspect symbol that throws fail
*
*
*
*
*
*
...
# Subtest: sync throw fails at second
not ok 2 - sync throw fails at second
Expand All @@ -491,6 +498,10 @@ not ok 53 - custom inspect symbol that throws fail
*
*
*
*
*
*
*
...
1..2
not ok 54 - subtest sync throw fails
Expand Down Expand Up @@ -565,6 +576,8 @@ not ok 56 - describe async throw fails
failureType: 'testTimeoutFailure'
error: 'test timed out after 5ms'
code: 'ERR_TEST_FAILURE'
stack: |-
*
...
# Subtest: timed out callback test
not ok 2 - timed out callback test
Expand Down

0 comments on commit fc19407

Please sign in to comment.