fix(): workflows concurrency (#13645)
This commit is contained in:
committed by
GitHub
parent
ca334b7cc1
commit
76aa4a48b3
@@ -207,7 +207,6 @@ describe("Transaction Orchestrator", () => {
|
||||
},
|
||||
{
|
||||
action: "three",
|
||||
async: true,
|
||||
maxRetries: 0,
|
||||
next: {
|
||||
action: "five",
|
||||
@@ -228,24 +227,14 @@ describe("Transaction Orchestrator", () => {
|
||||
|
||||
await strategy.resume(transaction)
|
||||
|
||||
expect(transaction.getErrors()).toHaveLength(2)
|
||||
expect(transaction.getErrors()).toHaveLength(1)
|
||||
expect(transaction.getErrors()).toEqual([
|
||||
{
|
||||
action: "three",
|
||||
error: {
|
||||
error: expect.objectContaining({
|
||||
message: "Step 3 failed",
|
||||
name: "Error",
|
||||
stack: expect.any(String),
|
||||
},
|
||||
handlerType: "invoke",
|
||||
},
|
||||
{
|
||||
action: "three",
|
||||
error: expect.objectContaining({
|
||||
message: expect.stringContaining(
|
||||
"Converting circular structure to JSON"
|
||||
),
|
||||
stack: expect.any(String),
|
||||
}),
|
||||
handlerType: "invoke",
|
||||
},
|
||||
@@ -1052,6 +1041,8 @@ describe("Transaction Orchestrator", () => {
|
||||
|
||||
await strategy.resume(transaction)
|
||||
|
||||
await new Promise((resolve) => process.nextTick(resolve))
|
||||
|
||||
expect(mocks.one).toHaveBeenCalledTimes(1)
|
||||
expect(mocks.two).toHaveBeenCalledTimes(0)
|
||||
expect(transaction.getState()).toBe(TransactionState.INVOKING)
|
||||
@@ -1148,6 +1139,8 @@ describe("Transaction Orchestrator", () => {
|
||||
|
||||
await strategy.resume(transaction)
|
||||
|
||||
await new Promise((resolve) => process.nextTick(resolve))
|
||||
|
||||
expect(mocks.one).toHaveBeenCalledTimes(1)
|
||||
expect(mocks.compensateOne).toHaveBeenCalledTimes(0)
|
||||
expect(mocks.two).toHaveBeenCalledTimes(0)
|
||||
@@ -1171,6 +1164,8 @@ describe("Transaction Orchestrator", () => {
|
||||
transaction,
|
||||
})
|
||||
|
||||
await new Promise((resolve) => process.nextTick(resolve))
|
||||
|
||||
expect(resumedTransaction.getState()).toBe(TransactionState.COMPENSATING)
|
||||
expect(mocks.compensateOne).toHaveBeenCalledTimes(1)
|
||||
|
||||
@@ -1263,6 +1258,7 @@ describe("Transaction Orchestrator", () => {
|
||||
})
|
||||
|
||||
await strategy.resume(transaction)
|
||||
await new Promise((resolve) => process.nextTick(resolve))
|
||||
|
||||
expect(mocks.one).toHaveBeenCalledTimes(1)
|
||||
expect(mocks.compensateOne).toHaveBeenCalledTimes(1)
|
||||
@@ -1335,6 +1331,7 @@ describe("Transaction Orchestrator", () => {
|
||||
})
|
||||
|
||||
await strategy.resume(transaction)
|
||||
await new Promise((resolve) => process.nextTick(resolve))
|
||||
|
||||
expect(transaction.getState()).toBe(TransactionState.DONE)
|
||||
expect(mocks.one).toHaveBeenCalledTimes(1)
|
||||
|
||||
@@ -116,6 +116,8 @@ describe("WorkflowManager", () => {
|
||||
it("should continue an asyncronous transaction after reporting a successful step", async () => {
|
||||
const transaction = await flow.run("deliver-product", "t-id")
|
||||
|
||||
await new Promise((resolve) => process.nextTick(resolve))
|
||||
|
||||
expect(handlers.get("foo").invoke).toHaveBeenCalledTimes(1)
|
||||
expect(handlers.get("callExternal").invoke).toHaveBeenCalledTimes(1)
|
||||
expect(handlers.get("bar").invoke).toHaveBeenCalledTimes(0)
|
||||
@@ -135,6 +137,8 @@ describe("WorkflowManager", () => {
|
||||
it("should revert an asyncronous transaction after reporting a failure step", async () => {
|
||||
const transaction = await flow.run("deliver-product", "t-id")
|
||||
|
||||
await new Promise((resolve) => process.nextTick(resolve))
|
||||
|
||||
expect(handlers.get("foo").invoke).toHaveBeenCalledTimes(1)
|
||||
expect(handlers.get("callExternal").invoke).toHaveBeenCalledTimes(1)
|
||||
expect(handlers.get("bar").invoke).toHaveBeenCalledTimes(0)
|
||||
|
||||
@@ -158,6 +158,8 @@ describe("WorkflowManager", () => {
|
||||
const flow = new LocalWorkflow("deliver-product", container)
|
||||
const transaction = await flow.run("t-id")
|
||||
|
||||
await new Promise((resolve) => process.nextTick(resolve))
|
||||
|
||||
expect(handlers.get("foo").invoke).toHaveBeenCalledTimes(1)
|
||||
expect(handlers.get("callExternal").invoke).toHaveBeenCalledTimes(1)
|
||||
expect(handlers.get("bar").invoke).toHaveBeenCalledTimes(0)
|
||||
@@ -177,6 +179,8 @@ describe("WorkflowManager", () => {
|
||||
const flow = new LocalWorkflow("deliver-product", container)
|
||||
const transaction = await flow.run("t-id")
|
||||
|
||||
await new Promise((resolve) => process.nextTick(resolve))
|
||||
|
||||
expect(handlers.get("foo").invoke).toHaveBeenCalledTimes(1)
|
||||
expect(handlers.get("callExternal").invoke).toHaveBeenCalledTimes(1)
|
||||
expect(handlers.get("bar").invoke).toHaveBeenCalledTimes(0)
|
||||
|
||||
@@ -951,8 +951,10 @@ export class TransactionOrchestrator extends EventEmitter {
|
||||
this.executeSyncStep(promise, transaction, step, nextSteps)
|
||||
)
|
||||
} else {
|
||||
// Execute async step in background and continue the execution of the transaction
|
||||
this.executeAsyncStep(promise, transaction, step, nextSteps)
|
||||
// Execute async step in background as part of the next event loop cycle and continue the execution of the transaction
|
||||
process.nextTick(() =>
|
||||
this.executeAsyncStep(promise, transaction, step, nextSteps)
|
||||
)
|
||||
hasAsyncSteps = true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user