From c4cb0aafc67779fee5cb7bb61186d964aba5104c Mon Sep 17 00:00:00 2001 From: harold Date: Tue, 7 Sep 2021 15:33:27 -0400 Subject: [PATCH] Add (failing) test case for multiple mapper errors with stop on error - Add a failing test case to indicate that only 1 of the mapper errors is catchable when stop on error is true and many mappers throw an exception - With concurrent mappers it seems that exceptions should throw an AggregateError when stop on error is true and more than 1 concurrent mapper throws - the iteration of new input items should stop immediately, but all invoked mappers need to finish and all of their exceptions should be bundled and rejected at once - maybe? --- test.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test.js b/test.js index fdcb7c5..6815d06 100644 --- a/test.js +++ b/test.js @@ -225,3 +225,36 @@ test('catches exception from source iterator - 2nd item after 1st item mapper th t.is(input.index, 2); t.deepEqual(mappedValues, [0]); }); + +test('no unhandled rejected promises from mapper throws - infinite concurrency', async t => { + const input = [1, 2, 3]; + const mappedValues = []; + await t.throwsAsync( + pMap(input, async value => { + mappedValues.push(value); + await delay(100); + throw new Error(`Oops! ${value}`); + }), + {message: 'Some big AggregateError message'} + ); + // Note: all 3 mappers get invoked, all 3 throw, even with stop on error this + // should raise an AggregateError with all 3 exceptions instead of throwing 1 + // exception and hiding the other 2. + t.deepEqual(mappedValues, [1, 2, 3]); +}); + +test('no unhandled rejected promises from mapper throws - concurrency 1', async t => { + const input = [1, 2, 3]; + const mappedValues = []; + await t.throwsAsync( + pMap(input, async value => { + mappedValues.push(value); + await delay(100); + throw new Error(`Oops! ${value}`); + }, + {concurrency: 1}), + {message: 'Oops! 1'} + ); + t.deepEqual(mappedValues, [1]); +}); +