Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/utils/ConcurrentExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export async function executeConcurrent<T, R>(
return {
results,
durationMs,
successCount: items.length - errors.length,
successCount: completedCount,
failureCount: errors.length,
errors,
};
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/ConcurrentExecutor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,29 @@ describe('ConcurrentExecutor', () => {
expect(processedCount).toBeLessThanOrEqual(items.length);
});

it('should not count skipped items as successes when stopping on error', async () => {
const items = Array.from({ length: 10 }, (_, i) => i);
let processedCount = 0;

const result = await executeConcurrent(
items,
async (item) => {
processedCount++;
// The very first item fails, so nothing else is attempted.
throw new Error(`fail ${item}`);
},
{ concurrency: 1, stopOnError: true }
);

// Only one item was ever attempted (and it failed); the remaining 9
// were skipped and are neither successes nor failures.
expect(processedCount).toBe(1);
expect(result.failureCount).toBe(1);
// successCount must reflect actually-completed operations (0), not
// items.length - errors.length (which would wrongly report 9).
expect(result.successCount).toBe(0);
});

it('should limit concurrency', async () => {
const maxConcurrent = { current: 0, max: 0 };
const items = Array.from({ length: 10 }, (_, i) => i);
Expand Down
Loading