Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
improve workflow unit test

Signed-off-by: kaibocai <[email protected]>
  • Loading branch information
kaibocai committed Jan 7, 2024
1 parent 3a2649f commit 781a620
Show file tree
Hide file tree
Showing 19 changed files with 499 additions and 428 deletions.
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"test:e2e:common": "npm run test:e2e:common:client && npm run test:e2e:common:server",
"test:e2e:common:client": "./scripts/test-e2e-common.sh client",
"test:e2e:common:server": "./scripts/test-e2e-common.sh server",
"test:e2e:workflow": "npm run prebuild && TEST_SECRET_1=secret_val_1 TEST_SECRET_2=secret_val_2 dapr run --app-id workflow-test-suite --app-protocol grpc --dapr-grpc-port 4001 --components-path ./test/components/workflow -- jest --runInBand --detectOpenHandles --testMatch [ '**/test/e2e/workflow/workflow.test.ts' ]",
"test:e2e:workflow": "npm run prebuild && dapr run --app-id workflow-test-suite --app-protocol grpc --dapr-grpc-port 4001 --components-path ./test/components/workflow -- jest --runInBand --detectOpenHandles --testMatch [ '**/test/e2e/workflow/workflow.test.ts' ]",
"test:e2e:workflow:internal": "jest test/e2e/workflow --runInBand --detectOpenHandles",
"test:e2e:workflow:durabletask": "./scripts/test-e2e-workflow.sh",
"test:unit": "jest --runInBand --detectOpenHandles",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -11,6 +11,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import WorkflowActivityContext from "../runtime/WorkflowActivityContext";
import WorkflowActivityContext from "../../workflow/runtime/WorkflowActivityContext";

export type TWorkflowActivity<TInput, TOutput> = (context: WorkflowActivityContext, input: TInput) => TOutput;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import WorkflowContext from "../runtime/WorkflowContext";
import WorkflowContext from "../../workflow/runtime/WorkflowContext";
import { Task } from "kaibocai-durabletask-js/task/task";
import { TOutput } from "./InputOutput.type";

Expand Down
11 changes: 7 additions & 4 deletions src/workflow/client/WorkflowClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -15,7 +15,7 @@ import { TaskHubGrpcClient } from "kaibocai-durabletask-js";
import * as grpc from "@grpc/grpc-js";
import { WorkflowState } from "./WorkflowState";
import { generateInterceptors } from "../internal/ApiTokenClientInterceptor";
import { TWorkflow } from "../types/Workflow.type";
import { TWorkflow } from "../../types/workflow/Workflow.type";
import { getFunctionName } from "../internal";

export default class WorkflowClient {
Expand All @@ -27,10 +27,10 @@ export default class WorkflowClient {
* @param {grpc.ChannelOptions | undefined} options - Additional options for configuring the gRPC channel.
*/
constructor(hostAddress?: string, options?: grpc.ChannelOptions) {
this._innerClient = this._buildInnerClient(hostAddress, options);
this._innerClient = this.buildInnerClient(hostAddress, options);
}

_buildInnerClient(hostAddress = "127.0.0.1:50001", options: grpc.ChannelOptions = {}): TaskHubGrpcClient {
private buildInnerClient(hostAddress = "127.0.0.1:50001", options: grpc.ChannelOptions = {}): TaskHubGrpcClient {
const innerOptions = {
...options,
interceptors: [generateInterceptors(), ...(options?.interceptors ?? [])],
Expand All @@ -42,6 +42,9 @@ export default class WorkflowClient {
* Schedules a new workflow using the DurableTask client.
*
* @param {TWorkflow | string} workflow - The Workflow or the name of the workflow to be scheduled.
* @param {any} [input] - The input to be provided to the scheduled workflow.
* @param {string} [instanceId] - An optional unique identifier for the workflow instance.
* @param {Date} [startAt] - An optional date and time at which the workflow should start.
* @return {Promise<string>} A Promise resolving to the unique ID of the scheduled workflow instance.
*/
public async scheduleNewWorkflow(
Expand Down
2 changes: 1 addition & 1 deletion src/workflow/client/WorkflowFailureDetails.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
2 changes: 1 addition & 1 deletion src/workflow/client/WorkflowState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
6 changes: 3 additions & 3 deletions src/workflow/examples/activity-sequence.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -15,7 +15,7 @@ import WorkflowClient from "../client/WorkflowClient";
import WorkflowActivityContext from "../runtime/WorkflowActivityContext";
import WorkflowContext from "../runtime/WorkflowContext";
import WorkflowRuntime from "../runtime/WorkflowRuntime";
import { TWorkflow } from "../types/Workflow.type";
import { TWorkflow } from "../../types/workflow/Workflow.type";

(async () => {
const grpcEndpoint = "localhost:4001";
Expand All @@ -31,7 +31,7 @@ import { TWorkflow } from "../types/Workflow.type";

const result1 = yield ctx.callActivity(hello, "Tokyo");
cities.push(result1);
const result2 = yield ctx.callActivity(hello, "Seattle"); // Correct the spelling of "Seattle"
const result2 = yield ctx.callActivity(hello, "Seattle");
cities.push(result2);
const result3 = yield ctx.callActivity(hello, "London");
cities.push(result3);
Expand Down
4 changes: 2 additions & 2 deletions src/workflow/examples/fanout-fanin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -16,7 +16,7 @@ import WorkflowClient from "../client/WorkflowClient";
import WorkflowActivityContext from "../runtime/WorkflowActivityContext";
import WorkflowContext from "../runtime/WorkflowContext";
import WorkflowRuntime from "../runtime/WorkflowRuntime";
import { TWorkflow } from "../types/Workflow.type";
import { TWorkflow } from "../../types/workflow/Workflow.type";

// Wrap the entire code in an immediately-invoked async function
(async () => {
Expand Down
19 changes: 16 additions & 3 deletions src/workflow/examples/human-interaction.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
/*
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { Task } from "kaibocai-durabletask-js/task/task";
import WorkflowClient from "../client/WorkflowClient";
import WorkflowActivityContext from "../runtime/WorkflowActivityContext";
import WorkflowContext from "../runtime/WorkflowContext";
import WorkflowRuntime from "../runtime/WorkflowRuntime";
import { TWorkflow } from "../types/Workflow.type";
import { TWorkflow } from "../../types/workflow/Workflow.type";
import * as readlineSync from "readline-sync";

// Wrap the entire code in an immediately-invoked async function
Expand All @@ -25,8 +38,8 @@ import * as readlineSync from "readline-sync";

// Update the gRPC client and worker to use a local address and port
const grpcServerAddress = "localhost:4001";
let workflowClient: WorkflowClient = new WorkflowClient(grpcServerAddress);
let workflowRuntime: WorkflowRuntime = new WorkflowRuntime(grpcServerAddress);
const workflowClient: WorkflowClient = new WorkflowClient(grpcServerAddress);
const workflowRuntime: WorkflowRuntime = new WorkflowRuntime(grpcServerAddress);

//Activity function that sends an approval request to the manager
const sendApprovalRequest = async (_: WorkflowActivityContext, order: Order) => {
Expand Down
2 changes: 1 addition & 1 deletion src/workflow/internal/ApiTokenClientInterceptor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
8 changes: 4 additions & 4 deletions src/workflow/internal/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -11,9 +11,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { TInput, TOutput } from "../types/InputOutput.type";
import { TWorkflowActivity } from "../types/Activity.type";
import { TWorkflow } from "../types/Workflow.type";
import { TInput, TOutput } from "../../types/workflow/InputOutput.type";
import { TWorkflowActivity } from "../../types/workflow/Activity.type";
import { TWorkflow } from "../../types/workflow/Workflow.type";

export function getFunctionName(fn: TWorkflow | TWorkflowActivity<TInput, TOutput>): string {
return fn.name || fn.toString().match(/function\s*([^(]*)\(/)![1];
Expand Down
2 changes: 1 addition & 1 deletion src/workflow/runtime/WorkflowActivityContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
6 changes: 3 additions & 3 deletions src/workflow/runtime/WorkflowContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -15,8 +15,8 @@ import { OrchestrationContext } from "kaibocai-durabletask-js";
import { Task } from "kaibocai-durabletask-js/task/task";
import { TInput } from "kaibocai-durabletask-js/types/input.type";
import { TOutput } from "kaibocai-durabletask-js/types/output.type";
import { TWorkflowActivity } from "../types/Activity.type";
import { TWorkflow } from "../types/Workflow.type";
import { TWorkflowActivity } from "../../types/workflow/Activity.type";
import { TWorkflow } from "../../types/workflow/Workflow.type";
import { getFunctionName } from "../internal";
import { WhenAllTask } from "kaibocai-durabletask-js/task/when-all-task";
import { whenAll, whenAny } from "kaibocai-durabletask-js/task";
Expand Down
8 changes: 4 additions & 4 deletions src/workflow/runtime/WorkflowRuntime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -13,9 +13,9 @@ limitations under the License.

import * as grpc from "@grpc/grpc-js";
import { ActivityContext, OrchestrationContext, TaskHubGrpcWorker } from "kaibocai-durabletask-js";
import { TWorkflow } from "../types/Workflow.type";
import { TWorkflowActivity } from "../types/Activity.type";
import { TInput, TOutput } from "../types/InputOutput.type";
import { TWorkflow } from "../../types/workflow/Workflow.type";
import { TWorkflowActivity } from "../../types/workflow/Activity.type";
import { TInput, TOutput } from "../../types/workflow/InputOutput.type";
import WorkflowActivityContext from "./WorkflowActivityContext";
import WorkflowContext from "./WorkflowContext";
import { generateInterceptors } from "../internal/ApiTokenClientInterceptor";
Expand Down
2 changes: 1 addition & 1 deletion src/workflow/runtime/WorkflowRuntimeStatus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Dapr Authors
Copyright 2024 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
Loading

0 comments on commit 781a620

Please sign in to comment.