Skip to content

Commit e627732

Browse files
author
Shailesh Jagannath Padave
committed
Made few changes in test
1 parent 3757782 commit e627732

1 file changed

Lines changed: 37 additions & 16 deletions

File tree

src/core/__test__/executor.test.ts

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import {expect, describe, test, jest, beforeAll} from "@jest/globals";
1+
import {expect, describe, test, jest, beforeAll, afterEach, afterAll} from "@jest/globals";
22
import {Consistency, ReturnStrategy, SetVariableTaskDef, TaskType, WorkflowDef} from "../../common";
33
import { orkesConductorClient } from "../../orkes";
44
import { WorkflowExecutor } from "../executor";
55
import { v4 as uuidv4 } from "uuid";
66
import {MetadataClient} from "../metadataClient";
77
import {TestUtil} from "./utils/test-util";
8-
import {after} from "node:test";
98
import {TaskResultStatusEnum} from "../../common/open-api/models/TaskResultStatusEnum";
109
import {SignalResponse} from "../../common/open-api/models/SignalResponse";
1110

@@ -114,7 +113,6 @@ describe("Executor", () => {
114113
});
115114
});
116115

117-
118116
describe("Execute with Return Strategy and Consistency", () => {
119117
// Constants specific to this test suite
120118
const WORKFLOW_NAMES = {
@@ -130,6 +128,8 @@ describe("Execute with Return Strategy and Consistency", () => {
130128
let client: any;
131129
let executor: WorkflowExecutor;
132130
let metadataClient: MetadataClient;
131+
const workflowsToCleanup: {name: string, version: number}[] = [];
132+
const executionsToCleanup: string[] = [];
133133

134134
beforeAll(async () => {
135135
client = await clientPromise;
@@ -139,9 +139,21 @@ describe("Execute with Return Strategy and Consistency", () => {
139139

140140
// Register all test workflows
141141
await registerAllWorkflows();
142-
})
142+
});
143+
144+
afterEach(async () => {
145+
// Clean up executions first
146+
for (const executionId of executionsToCleanup) {
147+
try {
148+
await executor.terminate(executionId, "Test cleanup");
149+
} catch (e) {
150+
console.debug(`Failed to cleanup execution ${executionId}:`, e);
151+
}
152+
}
153+
executionsToCleanup.length = 0;
154+
});
143155

144-
after(async () => {
156+
afterAll(async () => {
145157
// Cleanup all workflows
146158
await cleanupAllWorkflows();
147159
});
@@ -154,24 +166,27 @@ describe("Execute with Return Strategy and Consistency", () => {
154166
TestUtil.registerWorkflow(WORKFLOW_NAMES.SUB_WF_2),
155167
TestUtil.registerWorkflow(WORKFLOW_NAMES.WAIT_SIGNAL_TEST)
156168
]);
169+
170+
// Add to cleanup list
171+
Object.values(WORKFLOW_NAMES).forEach(name => {
172+
workflowsToCleanup.push({name, version: 1});
173+
});
174+
157175
console.log('✓ All workflows registered successfully');
158176
} catch (error) {
159177
throw new Error(`Failed to register workflows: ${error}`);
160178
}
161179
}
162180

163181
async function cleanupAllWorkflows(): Promise<void> {
164-
const cleanupPromises = [
165-
TestUtil.unregisterWorkflow(WORKFLOW_NAMES.COMPLEX_WF, 1),
166-
TestUtil.unregisterWorkflow(WORKFLOW_NAMES.SUB_WF_1, 1),
167-
TestUtil.unregisterWorkflow(WORKFLOW_NAMES.SUB_WF_2, 1),
168-
TestUtil.unregisterWorkflow(WORKFLOW_NAMES.WAIT_SIGNAL_TEST, 1)
169-
];
182+
const cleanupPromises = workflowsToCleanup.map(({name, version}) =>
183+
TestUtil.unregisterWorkflow(name, version)
184+
);
170185

171186
const results = await Promise.allSettled(cleanupPromises);
172187
results.forEach((result, index) => {
173188
if (result.status === 'rejected') {
174-
console.warn(`Failed to cleanup workflow ${Object.values(WORKFLOW_NAMES)[index]}: ${result.reason}`);
189+
console.warn(`Failed to cleanup workflow ${workflowsToCleanup[index].name}: ${result.reason}`);
175190
}
176191
});
177192
console.log('✓ Cleanup completed');
@@ -241,7 +256,6 @@ describe("Execute with Return Strategy and Consistency", () => {
241256
}
242257
];
243258

244-
// Let's write one comprehensive test first, then replicate
245259
test("Should execute complex workflow with SYNC + TARGET_WORKFLOW and validate all aspects", async () => {
246260
const testCase = testCombinations[0]; // SYNC + TARGET_WORKFLOW
247261

@@ -262,6 +276,11 @@ describe("Execute with Return Strategy and Consistency", () => {
262276
// Convert to SignalResponse instance
263277
const result = Object.assign(new SignalResponse(), rawResult);
264278

279+
// Add to cleanup list
280+
if (result.workflowId) {
281+
executionsToCleanup.push(result.workflowId);
282+
}
283+
265284
console.log(`Started workflow with ID: ${result.workflowId} for strategy: ${testCase.name}`);
266285

267286
// ========== BASIC VALIDATIONS ==========
@@ -285,7 +304,6 @@ describe("Execute with Return Strategy and Consistency", () => {
285304
expect(result.status).toBeDefined();
286305
expect(result.createTime).toBeGreaterThan(0);
287306
expect(result.updateTime).toBeGreaterThan(0);
288-
//expect(result.updateTime).toBeGreaterThanOrEqual(result.createTime);
289307
expect(result.tasks).toBeDefined();
290308
expect(Array.isArray(result.tasks)).toBe(true);
291309
expect(result.tasks!.length).toBeGreaterThan(0);
@@ -317,7 +335,6 @@ describe("Execute with Return Strategy and Consistency", () => {
317335
expect(workflowFromResp.status).toEqual(result.status);
318336
expect(workflowFromResp.createTime).toEqual(result.createTime);
319337
expect(workflowFromResp.updateTime).toEqual(result.updateTime);
320-
//expect(workflowFromResp.tasks.length).toEqual(result.tasks!.length);
321338

322339
// Test that task helper methods throw errors
323340
expect(() => result.getBlockingTask()).toThrow('does not contain task details');
@@ -405,6 +422,11 @@ describe("Execute with Return Strategy and Consistency", () => {
405422
// Convert to SignalResponse instance
406423
const result = Object.assign(new SignalResponse(), rawResult);
407424

425+
// Add to cleanup list
426+
if (result.workflowId) {
427+
executionsToCleanup.push(result.workflowId);
428+
}
429+
408430
// Basic validations
409431
expect(result.responseType).toEqual(testCase.returnStrategy);
410432
expect(result.workflowId).toBeDefined();
@@ -451,5 +473,4 @@ describe("Execute with Return Strategy and Consistency", () => {
451473
});
452474
});
453475
});
454-
455476
});

0 commit comments

Comments
 (0)