Skip to content

Commit 56c019f

Browse files
committed
Added some tests
1 parent 5e9fdcc commit 56c019f

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"scripts": {
3737
"build": "rollup -c rollup.config.js",
3838
"test": "npm run lint && npm run coverage",
39-
"coverage": "npm run jest -- --coverage",
39+
"coverage": "npm run jest -- --coverage --verbose",
4040
"lint": "eslint -c .eslintrc.cjs \"src/**/*.mjs\"",
4141
"jest": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
4242
"docs": "jsdoc -c .jsdoc.json && node dev/docs-collect-version-numbers.cjs"

src/asyncGeneratorMap.test.mjs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ test('asyncGeneratorMap infinite sync operator', async () => {
597597
expect(results[2]).toStrictEqual(4)
598598
})
599599

600-
test('asyncGeneratorMap respect concurrency', async () => {
600+
test('asyncGeneratorMap blocks when concurrency reached', async () => {
601601
const callList = []
602602
const d = new Deferred()
603603
const p = asyncIterableToArray(asyncGeneratorMap(range(10), async (el, i) => {
@@ -611,3 +611,24 @@ test('asyncGeneratorMap respect concurrency', async () => {
611611
const result = await p
612612
expect(result).toStrictEqual(await asyncIterableToArray(range(10)))
613613
})
614+
615+
test('asyncGeneratorMap reaches concurrency', async () => {
616+
const expectedConcurrency = 10
617+
let currentConcurrency = 0
618+
let maxConcurrency = 0
619+
const d = new Deferred()
620+
const p = asyncIterableToArray(asyncGeneratorMap(range(100), async (el, i) => {
621+
currentConcurrency += 1
622+
maxConcurrency = Math.max(maxConcurrency, currentConcurrency)
623+
await d.promise
624+
currentConcurrency -= 1
625+
maxConcurrency = Math.max(maxConcurrency, currentConcurrency)
626+
return el
627+
}, expectedConcurrency))
628+
await asyncDelay()
629+
expect(maxConcurrency).toStrictEqual(expectedConcurrency)
630+
d.resolve()
631+
const result = await p
632+
expect(maxConcurrency).toStrictEqual(expectedConcurrency)
633+
expect(result).toStrictEqual(await asyncIterableToArray(range(100)))
634+
})

0 commit comments

Comments
 (0)