Skip to content

feat(batch): add option to not throw FullBatchFailureError when the entire batch fails #2711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: process partial response function call with asynchronous handle…
…r for full batch failure
  • Loading branch information
arnabrahman committed Jun 30, 2024
commit dba0f4474ebe21214733e67c7533eb98c21d358f
54 changes: 54 additions & 0 deletions packages/batch/tests/unit/processPartialResponse.test.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import {
processPartialResponse,
EventType,
UnexpectedBatchTypeError,
FullBatchFailureError,
} from '../../src/index.js';
import type {
BatchProcessingOptions,
@@ -90,6 +91,59 @@ describe('Function: processPartialResponse()', () => {
// Assess
expect(ret).toStrictEqual({ batchItemFailures: [] });
});

test('Process partial response function call with asynchronous handler for full batch failure', async () => {
// Prepare
const records = [sqsRecordFactory('fail'), sqsRecordFactory('fail')];
const batch = { Records: records };
const processor = new BatchProcessor(EventType.SQS);

// Act & Assess
await expect(
processPartialResponse(batch, asyncSqsRecordHandler, processor)
).rejects.toThrow(FullBatchFailureError);
});

test('Process partial response function call with asynchronous handler for full batch failure when `throwOnFullBatchFailure` is `true`', async () => {
// Prepare
const records = [sqsRecordFactory('fail'), sqsRecordFactory('fail')];
const batch = { Records: records };
const processor = new BatchProcessor(EventType.SQS);

// Act & Assess
await expect(
processPartialResponse(batch, asyncSqsRecordHandler, processor, {
...options,
throwOnFullBatchFailure: true,
})
).rejects.toThrow(FullBatchFailureError);
});

test('Process partial response function call with asynchronous handler for full batch failure when `throwOnFullBatchFailure` is `false`', async () => {
// Prepare
const records = [sqsRecordFactory('fail'), sqsRecordFactory('fail')];
const batch = { Records: records };
const processor = new BatchProcessor(EventType.SQS);

// Act
const response = await processPartialResponse(
batch,
asyncSqsRecordHandler,
processor,
{
...options,
throwOnFullBatchFailure: false,
}
);

// Assess
expect(response).toStrictEqual({
batchItemFailures: [
{ itemIdentifier: records[0].messageId },
{ itemIdentifier: records[1].messageId },
],
});
});
});

describe('Process partial response function call through handler', () => {