- Add Activepieces fork with SmoothSchedule custom piece - Create integrations app with Activepieces service layer - Add embed token endpoint for iframe integration - Create Automations page with embedded workflow builder - Add sidebar visibility fix for embed mode - Add list inactive customers endpoint to Public API - Include SmoothSchedule triggers: event created/updated/cancelled - Include SmoothSchedule actions: create/update/cancel events, list resources/services/customers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
100 lines
3.6 KiB
TypeScript
100 lines
3.6 KiB
TypeScript
import { FlowRunStatus } from '@activepieces/shared'
|
|
import { FlowExecutorContext } from '../../src/lib/handler/context/flow-execution-context'
|
|
import { runWithExponentialBackoff } from '../../src/lib/helper/error-handling'
|
|
import { buildCodeAction, generateMockEngineConstants } from '../handler/test-helper'
|
|
|
|
describe('runWithExponentialBackoff', () => {
|
|
const executionState = FlowExecutorContext.empty()
|
|
const action = buildCodeAction({
|
|
name: 'runtime',
|
|
input: {},
|
|
errorHandlingOptions: {
|
|
continueOnFailure: {
|
|
value: false,
|
|
},
|
|
retryOnFailure: {
|
|
value: true,
|
|
},
|
|
},
|
|
})
|
|
const constants = generateMockEngineConstants()
|
|
const requestFunction = jest.fn()
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks()
|
|
})
|
|
|
|
afterAll(() => {
|
|
jest.clearAllMocks()
|
|
})
|
|
|
|
it('should return resultExecutionState when verdict is not FAILED', async () => {
|
|
const resultExecutionState = FlowExecutorContext.empty().setVerdict({
|
|
status: FlowRunStatus.SUCCEEDED,
|
|
stopResponse: undefined,
|
|
})
|
|
requestFunction.mockResolvedValue(resultExecutionState)
|
|
|
|
const output = await runWithExponentialBackoff(executionState, action, constants, requestFunction)
|
|
|
|
expect(output).toEqual(resultExecutionState)
|
|
expect(requestFunction).toHaveBeenCalledWith({ action, executionState, constants })
|
|
})
|
|
|
|
|
|
it('should retry and return resultExecutionState when verdict is FAILED and retry is enabled', async () => {
|
|
const resultExecutionState = FlowExecutorContext.empty().setVerdict({
|
|
status: FlowRunStatus.FAILED,
|
|
failedStep: {
|
|
name: 'runtime',
|
|
displayName: 'runtime',
|
|
message: 'Custom Runtime Error',
|
|
},
|
|
})
|
|
|
|
requestFunction.mockResolvedValue(resultExecutionState)
|
|
|
|
const output = await runWithExponentialBackoff(executionState, action, constants, requestFunction)
|
|
|
|
expect(output).toEqual(resultExecutionState)
|
|
// Mock applies for the first attempt and second attempt is a real call which return success
|
|
expect(requestFunction).toHaveBeenCalledTimes(2)
|
|
expect(requestFunction).toHaveBeenCalledWith({ action, executionState, constants })
|
|
expect(requestFunction).toHaveBeenCalledWith({ action, executionState, constants })
|
|
})
|
|
|
|
it('should not retry and return resultExecutionState when verdict is FAILED but retry is disabled', async () => {
|
|
const resultExecutionState = FlowExecutorContext.empty().setVerdict({
|
|
status: FlowRunStatus.FAILED,
|
|
failedStep: {
|
|
name: 'runtime',
|
|
displayName: 'runtime',
|
|
message: 'Custom Runtime Error',
|
|
},
|
|
})
|
|
|
|
requestFunction.mockResolvedValue(resultExecutionState)
|
|
|
|
|
|
const actionWithDisabledRetry = buildCodeAction({
|
|
name: 'runtime',
|
|
input: {},
|
|
errorHandlingOptions: {
|
|
continueOnFailure: {
|
|
value: false,
|
|
},
|
|
retryOnFailure: {
|
|
value: false,
|
|
},
|
|
},
|
|
})
|
|
|
|
const output = await runWithExponentialBackoff(executionState, actionWithDisabledRetry, constants, requestFunction)
|
|
|
|
expect(output).toEqual(resultExecutionState)
|
|
expect(requestFunction).toHaveBeenCalledTimes(1)
|
|
expect(requestFunction).toHaveBeenCalledWith({ action: actionWithDisabledRetry, executionState, constants })
|
|
|
|
})
|
|
|
|
}) |