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
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: added additional tests
  • Loading branch information
Sudakatux committed Jul 12, 2023
commit ed50bd7ad2b6abed2e522f2548b5664f936d6362
126 changes: 90 additions & 36 deletions src/task/__tests__/TaskRunner.test.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,118 @@
import {jest, test, expect} from "@jest/globals"
import type {Mocked} from "jest-mock"
import { jest, test, expect } from "@jest/globals";
import type { Mocked } from "jest-mock";

import {RunnerArgs, TaskRunner} from "../TaskRunner"
import {mockLogger} from "./mockLogger"
import {TaskResourceService} from "../../common/open-api"
import { RunnerArgs, TaskRunner } from "../TaskRunner";
import { mockLogger } from "./mockLogger";
import { TaskResourceService } from "../../common/open-api";

const taskClientStub: Mocked<Pick<TaskResourceService, "poll" | "updateTask1">> = {
poll: jest.fn(),
updateTask1: jest.fn()
}
const mockTaskClient = taskClientStub as unknown as TaskResourceService

test('polls tasks', async () => {
const workerID = "worker-id"
test("polls tasks", async () => {
const taskClientStub: Mocked<
Pick<TaskResourceService, "poll" | "updateTask1">
> = {
poll: jest.fn(),
updateTask1: jest.fn(),
};
const mockTaskClient = taskClientStub as unknown as TaskResourceService;
const workerID = "worker-id";
const args: RunnerArgs = {
worker: {
taskDefName: "test",
execute: async ({inputData}) => {
execute: async ({ inputData }) => {
return {
outputData: {
"hello": "from worker",
...inputData
hello: "from worker",
...inputData,
},
status: "COMPLETED"
}
status: "COMPLETED",
};
},
},
options: {
pollInterval: 10,
domain: '',
domain: "",
concurrency: 1,
workerID
workerID,
},
logger: mockLogger,
taskResource: mockTaskClient
}
const workflowInstanceId = "fake-workflow-id"
const taskId = "fake-task-id"
taskResource: mockTaskClient,
};
const workflowInstanceId = "fake-workflow-id";
const taskId = "fake-task-id";
taskClientStub.poll.mockResolvedValue({
taskId,
workflowInstanceId,
status: "IN_PROGRESS",
reasonForIncompletion: undefined,
inputData: {
"input": "from workflow"
}
})
input: "from workflow",
},
});

const runner = new TaskRunner(args)
runner.startPolling()
const runner = new TaskRunner(args);
runner.startPolling();
await new Promise((r) => setTimeout(() => r(true), 10));
runner.stopPolling()
runner.stopPolling();
const expected = {
taskId,
workflowInstanceId,
status: "COMPLETED",
outputData: {
"hello": "from worker",
"input": "from workflow"
}
}
expect(taskClientStub.updateTask1).toHaveBeenCalledWith(expected)
})
hello: "from worker",
input: "from workflow",
},
};
expect(taskClientStub.updateTask1).toHaveBeenCalledWith(expected);
});

test("Should set the task as failed if the task has an error", async () => {
const taskClientStub: Mocked<
Pick<TaskResourceService, "poll" | "updateTask1">
> = {
poll: jest.fn(),
updateTask1: jest.fn(),
};
const mockTaskClient = taskClientStub as unknown as TaskResourceService;

const workerID = "worker-id";
const args: RunnerArgs = {
worker: {
taskDefName: "test",
execute: async ({ inputData }) => {
throw new Error("Error from worker");
},
},
options: {
pollInterval: 10,
domain: "",
concurrency: 1,
workerID,
},
logger: mockLogger,
taskResource: mockTaskClient,
};
const workflowInstanceId = "fake-workflow-id";
const taskId = "fake-task-id";
taskClientStub.poll.mockResolvedValue({
taskId,
workflowInstanceId,
status: "IN_PROGRESS",
reasonForIncompletion: undefined,
inputData: {
input: "from workflow",
},
});

const runner = new TaskRunner(args);
runner.startPolling();
await new Promise((r) => setTimeout(() => r(true), 10));
runner.stopPolling();
const expected = {
taskId,
workflowInstanceId,
status: "FAILED",
outputData: {
},
reasonForIncompletion: "Error from worker",
};
expect(taskClientStub.updateTask1).toHaveBeenCalledWith(expected);
});