Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose IsPolling. and Options from TaskManager, DNS Catching. #42

Merged
merged 27 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
62ee6ee
fix: expose isPolling
Sudakatux Jun 28, 2023
77f8be2
refactor: expose options.
Sudakatux Jun 28, 2023
242a0c5
feat: add additional tests
Sudakatux Jun 28, 2023
fe17b78
fix: linting
Sudakatux Jun 28, 2023
959fa82
refactor: execute wf sync
Sudakatux Jun 28, 2023
b801791
refactor: readability renamed getter
Sudakatux Jun 28, 2023
4976782
fix: serverUrl to secret
Sudakatux Jun 28, 2023
781148e
feat: added dns cache
Sudakatux Jul 7, 2023
40b75b9
refactor: moved noop logger to ConductorLogger
Sudakatux Jul 7, 2023
3e66b11
feat: added base client factory
Sudakatux Jul 7, 2023
7017a91
fix: types
Sudakatux Jul 7, 2023
7aefcff
fix: wrong dependency type
Sudakatux Jul 7, 2023
d0d708c
chore: format
Sudakatux Jul 7, 2023
d466d8e
Moving things arround
Sudakatux Jul 10, 2023
012062e
fix: imports
Sudakatux Jul 11, 2023
77d01ec
refactor: moved generators from its package
Sudakatux Jul 11, 2023
f6de47a
fix: re add jest config
Sudakatux Jul 11, 2023
66a2c76
refactor: use sync workflow in test
Sudakatux Jul 11, 2023
ec333a2
feat: split browser support
Sudakatux Jul 11, 2023
3d89ea9
fix: imports
Sudakatux Jul 11, 2023
50fd63d
feat: export catch utils
Sudakatux Jul 11, 2023
709c9c1
fix: increment timeout
Sudakatux Jul 11, 2023
a883571
fix: revert changes
Sudakatux Jul 11, 2023
daf5b1f
fix: revert change in CancelablePromise
Sudakatux Jul 12, 2023
07496f2
chore: linting
Sudakatux Jul 12, 2023
ed50bd7
feat: added additional tests
Sudakatux Jul 12, 2023
6849f19
chore: fix linting
Sudakatux Jul 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add additional tests
  • Loading branch information
Sudakatux committed Jun 28, 2023
commit 242a0c54b94fb88d879e97656a505de0b8a013fd
79 changes: 77 additions & 2 deletions src/task/__tests__/TaskManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { expect, describe, test, jest } from "@jest/globals";
import { OrkesApiConfig, orkesConductorClient } from "../../common";
import { OrkesApiConfig, orkesConductorClient, simpleTask } from "../../common";
import { WorkflowExecutor } from "../../core";
import { TaskManager } from "../TaskManager";
import { ConductorWorker } from "../Worker";
import { assert } from "console";

const playConfig: Partial<OrkesApiConfig> = {
keyId: `${process.env.KEY_ID}`,
Expand Down Expand Up @@ -90,7 +91,7 @@ describe("TaskManager", () => {
},
};

const manager = new TaskManager(client, [worker],{
const manager = new TaskManager(client, [worker], {
options: { pollInterval: 1500 },
});

Expand All @@ -103,4 +104,78 @@ describe("TaskManager", () => {
});
manager.stopPolling();
});

test("multi worker example", async () => {
const client = await clientPromise;

const executor = new WorkflowExecutor(client);
// just create a bunch of worker names
const workerNames: string[] = Array.from({ length: 3 })
.fill(0)
.map((_, i: number) => `taskman-multi-${1 + i}`);

// names to actual workers
const workers: ConductorWorker[] = workerNames.map((name) => ({
taskDefName: name,
execute: async () => {
return {
outputData: {
hello: "From your worker",
},
status: "COMPLETED",
};
},
}));

//create the manager with initial configuations
const manager = new TaskManager(client, workers, {
options: { pollInterval: 1500, concurrency: 2 },
logger: console,
});
// start polling
manager.startPolling();

expect(manager.isPolling).toBeTruthy();

const workflowName = "TaskManagerTestMulti";

// increase polling speed
manager.updatePollingOptions({ concurrency: 4 });

// create the workflow where we will run the test
await executor.registerWorkflow(true, {
name: workflowName,
version: 1,
ownerEmail: "developers@orkes.io",
tasks: workerNames.map((name) => simpleTask(name, name, {})),
inputParameters: [],
outputParameters: {},
timeoutSeconds: 0,
});

//Start workf
const { workflowId: executionId } = await executor.executeWorkflow(
{
name: workflowName,
version: 1,
},
workflowName,
1,
"identifierTaskManMulti"
);
expect(executionId).toBeDefined();

// decrease speed again
manager.updatePollingOptions({ pollInterval: 1000, concurrency: 1 });

const workflowStatus = await executor.getWorkflow(executionId!, true);

expect(workflowStatus.status).toEqual("COMPLETED");
manager.stopPolling();
await new Promise((r) => setTimeout(() => r(true), 1000));

expect(manager.isPolling).toBeFalsy();
expect(manager.options.concurrency).toBe(1);
expect(manager.options.pollInterval).toBe(1000);
});
});
77 changes: 77 additions & 0 deletions src/task/__tests__/TaskRunnerIntTest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { expect, describe, test, jest } from "@jest/globals";
import {
OrkesApiConfig,
orkesConductorClient,
WorkflowExecutor,
TaskRunner,
simpleTask,
} from "../../../";

const config: Partial<OrkesApiConfig> = {
keyId: `${process.env.KEY_ID}`,
keySecret: `${process.env.KEY_SECRET}`,
serverUrl: "https://pg-staging.orkesconductor.com/api",
coderabhigupta marked this conversation as resolved.
Show resolved Hide resolved
};

describe("TaskManager", () => {
const clientPromise = orkesConductorClient(config);

jest.setTimeout(10000);
test("worker example ", async () => {
const client = await clientPromise;
const executor = new WorkflowExecutor(client);

const taskRunner = new TaskRunner({
taskResource: client.taskResource,
worker: {
taskDefName: "task-manager-int-test",
execute: async () => {
return {
outputData: {
hello: "From your worker",
},
status: "COMPLETED",
};
},
},
options: {
pollInterval: 1000,
domain: undefined,
concurrency: 2,
workerID: "",
},
});
taskRunner.startPolling();

expect(taskRunner.isPolling).toEqual(true);
const workflowName = "task-manager-int-test-wf";
await executor.registerWorkflow(true, {
name: workflowName,
version: 1,
ownerEmail: "developers@orkes.io",
tasks: [simpleTask("task-manager-int-test", "task-manager-int-test", {})],
inputParameters: [],
outputParameters: {},
timeoutSeconds: 0,
});

const executionId = await executor.startWorkflow({
name:workflowName,
input: {},
version: 1,
});
await new Promise((r) => setTimeout(() => r(true), 900));
taskRunner.updateOptions({ concurrency: 1, pollInterval: 100 });
const workflowStatus = await executor.getWorkflow(executionId, true);

const [firstTask] = workflowStatus.tasks || [];
expect(firstTask?.taskType).toEqual("task-manager-int-test");
expect(workflowStatus.status).toEqual("COMPLETED");

taskRunner.stopPolling();

expect(taskRunner.isPolling).toEqual(false);
const taskDetails = await executor.getTask(firstTask?.taskId || "");
expect(taskDetails.status).toEqual("COMPLETED");
});
});