test(): Test the create product workflow compensation (#4716)
**What** Integration tests to validate the workflow compensation. Also, fix the transaction state when the workflow is compensating and some steps does not have any compensation
This commit is contained in:
@@ -74,9 +74,9 @@ export class DistributedTransaction {
|
||||
public modelId: string
|
||||
public transactionId: string
|
||||
|
||||
private errors: TransactionStepError[] = []
|
||||
private readonly errors: TransactionStepError[] = []
|
||||
|
||||
private context: TransactionContext = new TransactionContext()
|
||||
private readonly context: TransactionContext = new TransactionContext()
|
||||
|
||||
constructor(
|
||||
private flow: TransactionFlow,
|
||||
|
||||
@@ -7,8 +7,8 @@ import { TransactionStep, TransactionStepHandler } from "./transaction-step"
|
||||
import {
|
||||
TransactionHandlerType,
|
||||
TransactionState,
|
||||
TransactionStepStatus,
|
||||
TransactionStepsDefinition,
|
||||
TransactionStepStatus,
|
||||
} from "./types"
|
||||
|
||||
import { EventEmitter } from "events"
|
||||
@@ -233,9 +233,8 @@ export class TransactionOrchestrator extends EventEmitter {
|
||||
const stepDef = flow.steps[step]
|
||||
const curState = stepDef.getStates()
|
||||
if (
|
||||
(curState.state === TransactionState.DONE ||
|
||||
curState.status === TransactionStepStatus.PERMANENT_FAILURE) &&
|
||||
!stepDef.definition.noCompensation
|
||||
curState.state === TransactionState.DONE ||
|
||||
curState.status === TransactionStepStatus.PERMANENT_FAILURE
|
||||
) {
|
||||
stepDef.beginCompensation()
|
||||
stepDef.changeState(TransactionState.NOT_STARTED)
|
||||
@@ -334,6 +333,11 @@ export class TransactionOrchestrator extends EventEmitter {
|
||||
if (curState.state === TransactionState.NOT_STARTED) {
|
||||
if (step.isCompensating()) {
|
||||
step.changeState(TransactionState.COMPENSATING)
|
||||
|
||||
if (step.definition.noCompensation) {
|
||||
step.changeState(TransactionState.REVERTED)
|
||||
continue
|
||||
}
|
||||
} else if (flow.state === TransactionState.INVOKING) {
|
||||
step.changeState(TransactionState.INVOKING)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user