Skip to content

Commit 4d4cf09

Browse files
committed
fix tests
1 parent 50eeb60 commit 4d4cf09

2 files changed

Lines changed: 67 additions & 36 deletions

File tree

  • packages/modules

packages/modules/workflow-engine-inmemory/integration-tests/__tests__/index.spec.ts

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
143143
})
144144

145145
describe("Cancel transaction", function () {
146-
it("should cancel an ongoing execution with async unfinished yet step", async () => {
146+
it("should cancel an ongoing execution with async unfinished yet step", (done) => {
147147
const transactionId = "transaction-to-cancel-id"
148148
const step1 = createStep("step1", async () => {
149149
return new StepResponse("step1")
@@ -168,25 +168,39 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
168168
return new WorkflowResponse("finished")
169169
})
170170

171-
await workflowOrcModule.run(workflowId, {
172-
input: {},
173-
transactionId,
174-
})
175-
176-
await setTimeoutPromise(100)
177-
178-
await workflowOrcModule.cancel(workflowId, {
179-
transactionId,
180-
})
181-
182-
await setTimeoutPromise(1000)
183-
184-
const execution = await workflowOrcModule.listWorkflowExecutions({
185-
transaction_id: transactionId,
186-
})
171+
workflowOrcModule
172+
.run(workflowId, {
173+
input: {},
174+
transactionId,
175+
})
176+
.then(async () => {
177+
await setTimeoutPromise(100)
178+
179+
await workflowOrcModule.cancel(workflowId, {
180+
transactionId,
181+
})
182+
183+
workflowOrcModule.subscribe({
184+
workflowId,
185+
transactionId,
186+
subscriber: async (event) => {
187+
if (event.eventType === "onFinish") {
188+
const execution =
189+
await workflowOrcModule.listWorkflowExecutions({
190+
transaction_id: transactionId,
191+
})
192+
193+
expect(execution.length).toEqual(1)
194+
expect(execution[0].state).toEqual(
195+
TransactionState.REVERTED
196+
)
197+
done()
198+
}
199+
},
200+
})
201+
})
187202

188-
expect(execution.length).toEqual(1)
189-
expect(execution[0].state).toEqual(TransactionState.REVERTED)
203+
failTrap(done)
190204
})
191205

192206
it("should cancel a complete execution with a sync workflow running as async", async () => {

packages/modules/workflow-engine-redis/integration-tests/__tests__/index.spec.ts

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
151151

152152
describe("Testing basic workflow", function () {
153153
describe("Cancel transaction", function () {
154-
it("should cancel an ongoing execution with async unfinished yet step", async () => {
154+
it("should cancel an ongoing execution with async unfinished yet step", (done) => {
155155
const transactionId = "transaction-to-cancel-id"
156156
const step1 = createStep("step1", async () => {
157157
return new StepResponse("step1")
@@ -179,25 +179,42 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
179179
}
180180
)
181181

182-
await workflowOrcModule.run(workflowId, {
183-
input: {},
184-
transactionId,
185-
})
186-
187-
await setTimeout(100)
188-
189-
await workflowOrcModule.cancel(workflowId, {
190-
transactionId,
191-
})
182+
workflowOrcModule
183+
.run(workflowId, {
184+
input: {},
185+
transactionId,
186+
})
187+
.then(async () => {
188+
await setTimeout(100)
192189

193-
await setTimeout(1000)
190+
await workflowOrcModule.cancel(workflowId, {
191+
transactionId,
192+
})
194193

195-
const execution = await workflowOrcModule.listWorkflowExecutions({
196-
transaction_id: transactionId,
197-
})
194+
workflowOrcModule.subscribe({
195+
workflowId,
196+
transactionId,
197+
subscriber: async (event) => {
198+
if (event.eventType === "onFinish") {
199+
const execution =
200+
await workflowOrcModule.listWorkflowExecutions({
201+
transaction_id: transactionId,
202+
})
203+
204+
expect(execution.length).toEqual(1)
205+
expect(execution[0].state).toEqual(
206+
TransactionState.REVERTED
207+
)
208+
done()
209+
}
210+
},
211+
})
212+
})
198213

199-
expect(execution.length).toEqual(1)
200-
expect(execution[0].state).toEqual(TransactionState.REVERTED)
214+
failTrap(
215+
done,
216+
"should cancel an ongoing execution with async unfinished yet step"
217+
)
201218
})
202219

203220
it("should cancel a complete execution with a sync workflow running as async", async () => {

0 commit comments

Comments
 (0)