Skip to content

Commit

Permalink
Fix case where pending items flowing will not be decremented after an…
Browse files Browse the repository at this point in the history
… error
  • Loading branch information
Pedro Kehl committed Aug 8, 2024
1 parent b0fda08 commit a969329
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/integration/error.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { fromGenerator } from '../../src'
import { sleep } from '../../src/utils/sleep'
import { getNumberedArray } from '../mocks/array.mock'
import { getMockedGenerator, getThrowingGenerator } from '../mocks/generator.mock'

describe('Error Handling', () => {
Expand Down Expand Up @@ -65,4 +67,20 @@ describe('Error Handling', () => {
await expect(caminho.run()).rejects.toMatchObject({ message: 'Operator error' })
expect(caminho.getNumberOfItemsFlowing()).toBe(0)
})

test('Should not keep account the pending items in the flow after an error', async () => {
const operator = jest.fn()
.mockImplementationOnce(() => sleep(1))
.mockImplementationOnce(() => sleep(1))
.mockImplementationOnce(() => sleep(1))
.mockRejectedValueOnce(new Error('Operator error'))

const generator = getMockedGenerator(getNumberedArray(10))

const caminho = fromGenerator({ fn: generator, provides: 'number' }, { maxItemsFlowing: 5 })
.pipe({ fn: operator })

await expect(caminho.run()).rejects.toMatchObject({ message: 'Operator error' })
expect(caminho.getNumberOfItemsFlowing()).toBe(0)
})
})

0 comments on commit a969329

Please sign in to comment.