Skip to content

Commit d08e099

Browse files
fix executor v5 test issues related to naming, remove test utils class
1 parent df0597e commit d08e099

16 files changed

Lines changed: 406 additions & 445 deletions

integration-tests/common/TaskManager.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { simpleTask, taskDefinition, WorkflowExecutor } from "../../src/core";
33
import { orkesConductorClient } from "../../src/orkes";
44
import { TaskManager, ConductorWorker } from "../../src/task/index";
55
import { mockLogger } from "../utils/mockLogger";
6-
import { TestUtil } from "../utils/test-util";
6+
import { waitForWorkflowCompletion } from "../utils/waitForWorkflowCompletion";
77

88

99
const BASE_TIME = 1000;
@@ -51,7 +51,7 @@ describe("TaskManager", () => {
5151
version: 1,
5252
});
5353

54-
const workflowStatus = await TestUtil.waitForWorkflowCompletion(executor, executionId, BASE_TIME * 30);
54+
const workflowStatus = await waitForWorkflowCompletion(executor, executionId, BASE_TIME * 30);
5555

5656
expect(workflowStatus.status).toEqual("COMPLETED");
5757

@@ -103,7 +103,7 @@ describe("TaskManager", () => {
103103
correlationId: `${workflowName}-id`
104104
});
105105

106-
const workflowStatus = await TestUtil.waitForWorkflowCompletion(executor, status, BASE_TIME * 30);
106+
const workflowStatus = await waitForWorkflowCompletion(executor, status, BASE_TIME * 30);
107107

108108
expect(workflowStatus.status).toEqual("FAILED");
109109
expect(mockErrorHandler).toHaveBeenCalledTimes(1);
@@ -152,7 +152,7 @@ describe("TaskManager", () => {
152152
correlationId: `${workflowName}-id`
153153
});
154154

155-
const workflowStatus = await TestUtil.waitForWorkflowCompletion(executor, executionId!, BASE_TIME * 30);
155+
const workflowStatus = await waitForWorkflowCompletion(executor, executionId!, BASE_TIME * 30);
156156
expect(workflowStatus.status).toEqual("FAILED");
157157
await manager.stopPolling();
158158
});
@@ -217,7 +217,7 @@ describe("TaskManager", () => {
217217
// decrease speed again
218218
manager.updatePollingOptions({ pollInterval: BASE_TIME, concurrency: 1 });
219219

220-
const workflowStatus = await TestUtil.waitForWorkflowCompletion(executor, executionId, BASE_TIME * 30);
220+
const workflowStatus = await waitForWorkflowCompletion(executor, executionId, BASE_TIME * 30);
221221

222222
expect(workflowStatus.status).toEqual("COMPLETED");
223223
await manager.stopPolling();
@@ -343,7 +343,7 @@ describe("TaskManager", () => {
343343
// decrease speed again
344344
manager.updatePollingOptions({ pollInterval: BASE_TIME, concurrency: 1 });
345345

346-
const workflowStatus = await TestUtil.waitForWorkflowCompletion(executor, executionId, BASE_TIME * 30);
346+
const workflowStatus = await waitForWorkflowCompletion(executor, executionId, BASE_TIME * 30);
347347

348348
expect(workflowStatus.status).toEqual("COMPLETED");
349349
await manager.stopPolling();

integration-tests/common/TaskRunnerIntTest.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect, describe, test, jest } from "@jest/globals";
22
import { TaskRunner } from "../../src/task/TaskRunner";
33
import { WorkflowExecutor, simpleTask } from "../../src/core";
44
import { orkesConductorClient } from "../../src/orkes";
5-
import { TestUtil } from "../utils/test-util";
5+
import { waitForWorkflowStatus } from "../utils/waitForWorkflowStatus";
66

77
describe("TaskManager", () => {
88
const clientPromise = orkesConductorClient();
@@ -61,7 +61,7 @@ describe("TaskManager", () => {
6161

6262
taskRunner.updateOptions({ concurrency: 1, pollInterval: 100 });
6363

64-
const workflowStatus = await TestUtil.waitForWorkflowStatus(executor, executionId!, "COMPLETED");
64+
const workflowStatus = await waitForWorkflowStatus(executor, executionId!, "COMPLETED");
6565

6666
const [firstTask] = workflowStatus.tasks || [];
6767
expect(firstTask?.taskType).toEqual(taskName);

integration-tests/common/executor.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { SetVariableTaskDef, TaskType, WorkflowDef} from "../../src/common";
33
import { orkesConductorClient } from "../../src/orkes";
44
import { WorkflowExecutor } from "../../src/core/executor";
55
import { v4 as uuidv4 } from "uuid";
6-
import {TestUtil} from "../utils/test-util";
6+
import { waitForWorkflowStatus } from "../utils/waitForWorkflowStatus";
77
import { httpTask } from "../../src/core/sdk";
88
import { TaskClient } from "../../src/core/taskClient";
99

@@ -133,14 +133,14 @@ describe("Executor", () => {
133133
version: 1,
134134
});
135135

136-
const workflowStatusBefore = await TestUtil.waitForWorkflowStatus(executor, executionId, "RUNNING");
136+
const workflowStatusBefore = await waitForWorkflowStatus(executor, executionId, "RUNNING");
137137

138138
expect(["IN_PROGRESS", "SCHEDULED"]).toContain(workflowStatusBefore.tasks?.[0]?.status);
139139

140140
const taskClient = new TaskClient(client);
141141
taskClient.updateTaskResult(executionId, taskName, "COMPLETED", { hello: "From manuall api call updating task result" });
142142

143-
const workflowStatusAfter = await TestUtil.waitForWorkflowStatus(executor, executionId, "COMPLETED");
143+
const workflowStatusAfter = await waitForWorkflowStatus(executor, executionId, "COMPLETED");
144144

145145
expect(workflowStatusAfter.tasks?.[0]?.status).toEqual("COMPLETED");
146146
});
@@ -166,7 +166,7 @@ describe("Executor", () => {
166166
version: 1,
167167
});
168168

169-
const workflowStatus = await TestUtil.waitForWorkflowStatus(executor, executionId, "COMPLETED");
169+
const workflowStatus = await waitForWorkflowStatus(executor, executionId, "COMPLETED");
170170
expect(["FAILED", "COMPLETED_WITH_ERRORS"]).toContain(workflowStatus.tasks?.[0]?.status);
171171
});
172172
});

integration-tests/common/readme.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { orkesConductorClient } from "../../src/orkes";
33
import { WorkflowExecutor, simpleTask, generate } from "../../src/core";
44
import { TaskType } from "../../src/common";
55
import { TaskRunner } from "../../src/task";
6-
import { TestUtil } from "../utils/test-util";
6+
import { waitForWorkflowStatus } from "../utils/waitForWorkflowStatus";
77

88
describe("TaskManager", () => {
99
const clientPromise = orkesConductorClient();
@@ -54,7 +54,7 @@ describe("TaskManager", () => {
5454
version: 1,
5555
});
5656

57-
const workflowStatus = await TestUtil.waitForWorkflowStatus(executor, executionId, "COMPLETED");
57+
const workflowStatus = await waitForWorkflowStatus(executor, executionId, "COMPLETED");
5858

5959
const [firstTask] = workflowStatus.tasks || [];
6060
expect(firstTask?.taskType).toEqual(taskName);
@@ -162,7 +162,7 @@ describe("TaskManager", () => {
162162
`workflow${sumTwoNumbers.name}`
163163
);
164164

165-
const workflowStatus = await TestUtil.waitForWorkflowStatus(executor, executionId!, "COMPLETED");
165+
const workflowStatus = await waitForWorkflowStatus(executor, executionId!, "COMPLETED");
166166

167167
expect(workflowStatus.status).toEqual("COMPLETED");
168168
expect(workflowStatus.output?.result).toEqual(3);

integration-tests/utils/test-util.ts

Lines changed: 0 additions & 124 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type { WorkflowExecutor } from "../../src/core/executor";
2+
3+
// Helper function to wait for workflow completion
4+
export const waitForWorkflowCompletion = async (
5+
executor: WorkflowExecutor,
6+
workflowId: string,
7+
maxWaitMs: number = 300000, // 5 minutes default
8+
pollIntervalMs: number = 100 // 100ms default
9+
) => {
10+
const startTime = Date.now();
11+
12+
while (Date.now() - startTime < maxWaitMs) {
13+
try {
14+
const workflowStatus = await executor.getWorkflow(workflowId, true);
15+
16+
// Check if workflow is in a terminal state
17+
if (
18+
["COMPLETED", "FAILED", "TERMINATED", "TIMED_OUT"].includes(
19+
workflowStatus.status!
20+
)
21+
) {
22+
console.debug(
23+
`Workflow ${workflowId} reached terminal state: ${workflowStatus.status}`
24+
);
25+
return workflowStatus;
26+
}
27+
28+
console.debug(
29+
`Workflow ${workflowId} status: ${workflowStatus.status}, waiting...`
30+
);
31+
32+
// Wait before next poll
33+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
34+
} catch (error) {
35+
console.warn(`Error checking workflow status for ${workflowId}:`, error);
36+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
37+
}
38+
}
39+
40+
throw new Error(
41+
`Workflow ${workflowId} did not complete within ${maxWaitMs}ms`
42+
);
43+
};
44+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Wait for workflow to reach expected status
3+
*/
4+
export const waitForWorkflowStatus = async (
5+
workflowClient: any,
6+
workflowId: string,
7+
expectedStatus: string,
8+
maxWaitTimeMs: number = 15000,
9+
pollIntervalMs: number = 1000
10+
): Promise<any> => {
11+
const startTime = Date.now();
12+
13+
while (Date.now() - startTime < maxWaitTimeMs) {
14+
try {
15+
const workflow = await workflowClient.getWorkflow(workflowId, true);
16+
17+
if (workflow.status === expectedStatus) {
18+
return workflow;
19+
}
20+
21+
if (workflow.status === "FAILED" || workflow.status === "TERMINATED") {
22+
throw new Error(
23+
`Workflow ended in unexpected state: ${workflow.status}`
24+
);
25+
}
26+
27+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
28+
} catch (error) {
29+
throw new Error(`Failed to get workflow status: ${error}`);
30+
}
31+
}
32+
33+
throw new Error(
34+
`Workflow did not reach status ${expectedStatus} within ${maxWaitTimeMs}ms`
35+
);
36+
};

0 commit comments

Comments
 (0)