Skip to content

Commit

Permalink
Add (failing) test case for multiple mapper errors with stop on error
Browse files Browse the repository at this point in the history
- 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?
  • Loading branch information
huntharo committed Sep 12, 2021
1 parent 5ee5d93 commit c4cb0aa
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test.js
Expand Up @@ -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]);
});

0 comments on commit c4cb0aa

Please sign in to comment.