@temporalio/core-bridge 1.14.2-canary-release-testing.0 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +794 -650
- package/bridge-macros/src/derive_tryintojs.rs +40 -0
- package/lib/native.d.ts +24 -3
- package/package.json +4 -4
- package/releases/aarch64-apple-darwin/index.node +0 -0
- package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
- package/releases/x86_64-apple-darwin/index.node +0 -0
- package/releases/x86_64-pc-windows-msvc/index.node +0 -0
- package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
- package/sdk-core/.github/workflows/per-pr.yml +6 -6
- package/sdk-core/AGENTS.md +42 -31
- package/sdk-core/Cargo.toml +4 -1
- package/sdk-core/README.md +19 -13
- package/sdk-core/crates/client/Cargo.toml +4 -0
- package/sdk-core/crates/client/README.md +139 -0
- package/sdk-core/crates/client/src/async_activity_handle.rs +297 -0
- package/sdk-core/crates/client/src/callback_based.rs +7 -0
- package/sdk-core/crates/client/src/errors.rs +294 -0
- package/sdk-core/crates/client/src/{raw.rs → grpc.rs} +370 -159
- package/sdk-core/crates/client/src/lib.rs +920 -1326
- package/sdk-core/crates/client/src/metrics.rs +24 -33
- package/sdk-core/crates/client/src/options_structs.rs +457 -0
- package/sdk-core/crates/client/src/replaceable.rs +5 -4
- package/sdk-core/crates/client/src/request_extensions.rs +8 -9
- package/sdk-core/crates/client/src/retry.rs +99 -54
- package/sdk-core/crates/client/src/{worker/mod.rs → worker.rs} +104 -29
- package/sdk-core/crates/client/src/workflow_handle.rs +826 -0
- package/sdk-core/crates/common/Cargo.toml +62 -3
- package/sdk-core/crates/common/build.rs +742 -12
- package/sdk-core/crates/common/protos/api_upstream/.github/workflows/ci.yml +2 -0
- package/sdk-core/crates/common/protos/api_upstream/.github/workflows/create-release.yml +0 -5
- package/sdk-core/crates/common/protos/api_upstream/Makefile +2 -1
- package/sdk-core/crates/common/protos/api_upstream/README.md +8 -0
- package/sdk-core/crates/common/protos/api_upstream/cmd/check-path-conflicts/main.go +137 -0
- package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv2.json +3329 -2647
- package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv3.yaml +2734 -708
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/activity/v1/message.proto +155 -3
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/command/v1/message.proto +26 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/common/v1/message.proto +8 -1
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/deployment/v1/message.proto +27 -1
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/activity.proto +81 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/event_type.proto +4 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +4 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +15 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/workflow.proto +63 -15
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/errordetails/v1/message.proto +8 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/failure/v1/message.proto +1 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/history/v1/message.proto +111 -17
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/namespace/v1/message.proto +21 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/nexus/v1/message.proto +20 -1
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +4 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/schedule/v1/message.proto +2 -2
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +2 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/worker/v1/message.proto +4 -7
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflow/v1/message.proto +80 -22
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +347 -23
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +242 -43
- package/sdk-core/crates/common/protos/local/temporal/sdk/core/core_interface.proto +15 -0
- package/sdk-core/crates/common/protos/local/temporal/sdk/core/nexus/nexus.proto +9 -2
- package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +8 -0
- package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +22 -5
- package/sdk-core/crates/common/src/activity_definition.rs +20 -0
- package/sdk-core/crates/common/src/data_converters.rs +770 -0
- package/sdk-core/crates/common/src/envconfig.rs +5 -0
- package/sdk-core/crates/common/src/lib.rs +15 -211
- package/sdk-core/crates/common/src/payload_visitor.rs +648 -0
- package/sdk-core/crates/common/src/priority.rs +110 -0
- package/sdk-core/crates/common/src/protos/canned_histories.rs +19 -0
- package/sdk-core/crates/common/src/protos/history_builder.rs +45 -0
- package/sdk-core/crates/common/src/protos/history_info.rs +2 -0
- package/sdk-core/crates/common/src/protos/mod.rs +134 -27
- package/sdk-core/crates/common/src/protos/task_token.rs +3 -3
- package/sdk-core/crates/common/src/protos/utilities.rs +11 -0
- package/sdk-core/crates/{sdk-core → common}/src/telemetry/log_export.rs +11 -16
- package/sdk-core/crates/common/src/telemetry/metrics/core.rs +125 -0
- package/sdk-core/crates/common/src/telemetry/metrics.rs +272 -225
- package/sdk-core/crates/{sdk-core → common}/src/telemetry/otel.rs +8 -13
- package/sdk-core/crates/{sdk-core → common}/src/telemetry/prometheus_meter.rs +49 -50
- package/sdk-core/crates/{sdk-core → common}/src/telemetry/prometheus_server.rs +2 -3
- package/sdk-core/crates/common/src/telemetry.rs +278 -19
- package/sdk-core/crates/common/src/worker.rs +68 -636
- package/sdk-core/crates/common/src/workflow_definition.rs +60 -0
- package/sdk-core/crates/macros/Cargo.toml +5 -1
- package/sdk-core/crates/macros/src/activities_definitions.rs +585 -0
- package/sdk-core/crates/macros/src/fsm_impl.rs +507 -0
- package/sdk-core/crates/macros/src/lib.rs +138 -512
- package/sdk-core/crates/macros/src/macro_utils.rs +106 -0
- package/sdk-core/crates/macros/src/workflow_definitions.rs +1224 -0
- package/sdk-core/crates/sdk/Cargo.toml +19 -6
- package/sdk-core/crates/sdk/README.md +415 -0
- package/sdk-core/crates/sdk/src/activities.rs +417 -0
- package/sdk-core/crates/sdk/src/interceptors.rs +1 -1
- package/sdk-core/crates/sdk/src/lib.rs +759 -442
- package/sdk-core/crates/sdk/src/workflow_context/options.rs +64 -35
- package/sdk-core/crates/sdk/src/workflow_context.rs +1033 -289
- package/sdk-core/crates/sdk/src/workflow_future.rs +277 -213
- package/sdk-core/crates/sdk/src/workflows.rs +711 -0
- package/sdk-core/crates/sdk-core/Cargo.toml +59 -65
- package/sdk-core/crates/sdk-core/benches/workflow_replay_bench.rs +45 -54
- package/sdk-core/crates/sdk-core/machine_coverage/ActivityMachine_Coverage.puml +1 -1
- package/sdk-core/crates/sdk-core/src/abstractions.rs +6 -10
- package/sdk-core/crates/sdk-core/src/core_tests/activity_tasks.rs +6 -5
- package/sdk-core/crates/sdk-core/src/core_tests/mod.rs +22 -21
- package/sdk-core/crates/sdk-core/src/core_tests/queries.rs +21 -25
- package/sdk-core/crates/sdk-core/src/core_tests/replay_flag.rs +7 -10
- package/sdk-core/crates/sdk-core/src/core_tests/updates.rs +14 -17
- package/sdk-core/crates/sdk-core/src/core_tests/workers.rs +647 -27
- package/sdk-core/crates/sdk-core/src/core_tests/workflow_tasks.rs +46 -41
- package/sdk-core/crates/sdk-core/src/ephemeral_server/mod.rs +13 -16
- package/sdk-core/crates/sdk-core/src/histfetch.rs +20 -10
- package/sdk-core/crates/sdk-core/src/lib.rs +60 -123
- package/sdk-core/crates/sdk-core/src/pollers/mod.rs +4 -9
- package/sdk-core/crates/sdk-core/src/pollers/poll_buffer.rs +411 -32
- package/sdk-core/crates/sdk-core/src/protosext/mod.rs +2 -2
- package/sdk-core/crates/sdk-core/src/replay/mod.rs +14 -5
- package/sdk-core/crates/sdk-core/src/telemetry/metrics.rs +183 -198
- package/sdk-core/crates/sdk-core/src/telemetry/mod.rs +3 -281
- package/sdk-core/crates/sdk-core/src/test_help/integ_helpers.rs +35 -16
- package/sdk-core/crates/sdk-core/src/test_help/unit_helpers.rs +3 -6
- package/sdk-core/crates/sdk-core/src/worker/activities/activity_heartbeat_manager.rs +1 -0
- package/sdk-core/crates/sdk-core/src/worker/activities/local_activities.rs +11 -14
- package/sdk-core/crates/sdk-core/src/worker/activities.rs +16 -19
- package/sdk-core/crates/sdk-core/src/worker/client/mocks.rs +11 -5
- package/sdk-core/crates/sdk-core/src/worker/client.rs +104 -86
- package/sdk-core/crates/sdk-core/src/worker/heartbeat.rs +10 -14
- package/sdk-core/crates/sdk-core/src/worker/mod.rs +1175 -241
- package/sdk-core/crates/sdk-core/src/worker/nexus.rs +150 -23
- package/sdk-core/crates/sdk-core/src/worker/slot_provider.rs +2 -2
- package/sdk-core/crates/sdk-core/src/worker/tuner/fixed_size.rs +2 -2
- package/sdk-core/crates/sdk-core/src/worker/tuner/resource_based.rs +25 -27
- package/sdk-core/crates/sdk-core/src/worker/tuner.rs +64 -44
- package/sdk-core/crates/sdk-core/src/worker/workflow/driven_workflow.rs +9 -3
- package/sdk-core/crates/sdk-core/src/worker/workflow/machines/patch_state_machine.rs +5 -8
- package/sdk-core/crates/sdk-core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +21 -22
- package/sdk-core/crates/sdk-core/src/worker/workflow/machines/workflow_machines.rs +28 -4
- package/sdk-core/crates/sdk-core/src/worker/workflow/managed_run.rs +20 -41
- package/sdk-core/crates/sdk-core/src/worker/workflow/mod.rs +50 -9
- package/sdk-core/crates/sdk-core/src/worker/workflow/run_cache.rs +4 -7
- package/sdk-core/crates/sdk-core/src/worker/workflow/wft_extraction.rs +2 -4
- package/sdk-core/crates/sdk-core/src/worker/workflow/wft_poller.rs +8 -9
- package/sdk-core/crates/sdk-core/src/worker/workflow/workflow_stream.rs +1 -3
- package/sdk-core/crates/sdk-core/tests/activities_procmacro.rs +6 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/basic_pass.rs +54 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/invalid_self_type_fail.rs +18 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/invalid_self_type_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/missing_context_fail.rs +14 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/missing_context_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/multi_arg_pass.rs +48 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/no_input_pass.rs +14 -0
- package/sdk-core/crates/sdk-core/tests/activities_trybuild/no_return_type_pass.rs +19 -0
- package/sdk-core/crates/sdk-core/tests/cloud_tests.rs +14 -5
- package/sdk-core/crates/sdk-core/tests/common/activity_functions.rs +55 -0
- package/sdk-core/crates/sdk-core/tests/common/mod.rs +281 -236
- package/sdk-core/crates/sdk-core/tests/common/workflows.rs +41 -28
- package/sdk-core/crates/sdk-core/tests/global_metric_tests.rs +9 -14
- package/sdk-core/crates/sdk-core/tests/heavy_tests/fuzzy_workflow.rs +73 -66
- package/sdk-core/crates/sdk-core/tests/heavy_tests.rs +306 -268
- package/sdk-core/crates/sdk-core/tests/integ_tests/async_activity_client_tests.rs +230 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/client_tests.rs +94 -57
- package/sdk-core/crates/sdk-core/tests/integ_tests/data_converter_tests.rs +381 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +37 -38
- package/sdk-core/crates/sdk-core/tests/integ_tests/heartbeat_tests.rs +49 -40
- package/sdk-core/crates/sdk-core/tests/integ_tests/metrics_tests.rs +447 -300
- package/sdk-core/crates/sdk-core/tests/integ_tests/pagination_tests.rs +50 -45
- package/sdk-core/crates/sdk-core/tests/integ_tests/polling_tests.rs +157 -157
- package/sdk-core/crates/sdk-core/tests/integ_tests/queries_tests.rs +103 -89
- package/sdk-core/crates/sdk-core/tests/integ_tests/update_tests.rs +609 -463
- package/sdk-core/crates/sdk-core/tests/integ_tests/visibility_tests.rs +80 -62
- package/sdk-core/crates/sdk-core/tests/integ_tests/worker_heartbeat_tests.rs +389 -265
- package/sdk-core/crates/sdk-core/tests/integ_tests/worker_tests.rs +250 -185
- package/sdk-core/crates/sdk-core/tests/integ_tests/worker_versioning_tests.rs +52 -49
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_client_tests.rs +180 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/activities.rs +437 -327
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +82 -58
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +56 -30
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +364 -251
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/client_interactions.rs +552 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +110 -46
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +243 -149
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/eager.rs +98 -32
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +1475 -1040
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +73 -43
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +402 -245
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/patches.rs +343 -207
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/queries.rs +415 -0
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/replay.rs +96 -36
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/resets.rs +155 -140
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/signals.rs +183 -113
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +85 -44
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/timers.rs +142 -48
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +73 -56
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests.rs +365 -242
- package/sdk-core/crates/sdk-core/tests/main.rs +22 -16
- package/sdk-core/crates/sdk-core/tests/manual_tests.rs +233 -187
- package/sdk-core/crates/sdk-core/tests/runner.rs +4 -6
- package/sdk-core/crates/sdk-core/tests/shared_tests/mod.rs +73 -27
- package/sdk-core/crates/sdk-core/tests/shared_tests/priority.rs +107 -84
- package/sdk-core/crates/sdk-core/tests/workflows_procmacro.rs +6 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/async_query_fail.rs +26 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/async_query_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/basic_pass.rs +49 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/minimal_pass.rs +21 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/mut_query_fail.rs +26 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/mut_query_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/sync_run_fail.rs +21 -0
- package/sdk-core/crates/sdk-core/tests/workflows_trybuild/sync_run_fail.stderr +5 -0
- package/sdk-core/crates/sdk-core-c-bridge/Cargo.toml +8 -1
- package/sdk-core/crates/sdk-core-c-bridge/include/temporal-sdk-core-c-bridge.h +37 -26
- package/sdk-core/crates/sdk-core-c-bridge/src/client.rs +180 -87
- package/sdk-core/crates/sdk-core-c-bridge/src/lib.rs +89 -5
- package/sdk-core/crates/sdk-core-c-bridge/src/metric.rs +10 -16
- package/sdk-core/crates/sdk-core-c-bridge/src/runtime.rs +59 -67
- package/sdk-core/crates/sdk-core-c-bridge/src/testing.rs +10 -10
- package/sdk-core/crates/sdk-core-c-bridge/src/tests/context.rs +57 -22
- package/sdk-core/crates/sdk-core-c-bridge/src/tests/mod.rs +108 -12
- package/sdk-core/crates/sdk-core-c-bridge/src/tests/utils.rs +9 -52
- package/sdk-core/crates/sdk-core-c-bridge/src/worker.rs +74 -91
- package/sdk-core/rustfmt.toml +2 -1
- package/src/client.rs +206 -289
- package/src/helpers/try_into_js.rs +88 -2
- package/src/metrics.rs +277 -35
- package/src/runtime.rs +94 -45
- package/src/testing.rs +9 -16
- package/src/worker.rs +86 -68
- package/ts/native.ts +39 -3
- package/sdk-core/crates/client/src/workflow_handle/mod.rs +0 -212
- package/sdk-core/crates/common/src/errors.rs +0 -85
- package/sdk-core/crates/common/tests/worker_task_types_test.rs +0 -129
- package/sdk-core/crates/macros/LICENSE.txt +0 -21
- package/sdk-core/crates/sdk/src/activity_context.rs +0 -238
- package/sdk-core/crates/sdk/src/app_data.rs +0 -37
- package/sdk-core/crates/sdk-core/tests/integ_tests/activity_functions.rs +0 -5
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +0 -61
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
use crate::common::{CoreWfStarter, build_fake_sdk, mock_sdk, mock_sdk_cfg};
|
|
2
2
|
use anyhow::anyhow;
|
|
3
3
|
use assert_matches::assert_matches;
|
|
4
|
-
use std::time::Duration;
|
|
5
|
-
use temporalio_client::{
|
|
4
|
+
use std::{sync::Arc, time::Duration};
|
|
5
|
+
use temporalio_client::{UntypedWorkflow, WorkflowCancelOptions, WorkflowStartOptions};
|
|
6
6
|
use temporalio_common::{
|
|
7
|
-
Worker,
|
|
8
7
|
protos::{
|
|
9
8
|
TestHistoryBuilder, canned_histories,
|
|
10
9
|
coresdk::{
|
|
@@ -25,7 +24,6 @@ use temporalio_common::{
|
|
|
25
24
|
workflow_completion::WorkflowActivationCompletion,
|
|
26
25
|
},
|
|
27
26
|
temporal::api::{
|
|
28
|
-
common::v1::Payload,
|
|
29
27
|
enums::v1::{CommandType, EventType, ParentClosePolicy},
|
|
30
28
|
history::v1::{
|
|
31
29
|
StartChildWorkflowExecutionFailedEventAttributes,
|
|
@@ -36,8 +34,10 @@ use temporalio_common::{
|
|
|
36
34
|
},
|
|
37
35
|
worker::WorkerTaskTypes,
|
|
38
36
|
};
|
|
37
|
+
use temporalio_macros::{workflow, workflow_methods};
|
|
39
38
|
use temporalio_sdk::{
|
|
40
|
-
CancellableFuture, ChildWorkflowOptions, Signal,
|
|
39
|
+
CancellableFuture, ChildWorkflowOptions, Signal, WorkflowContext, WorkflowResult,
|
|
40
|
+
WorkflowTermination,
|
|
41
41
|
};
|
|
42
42
|
use temporalio_sdk_core::{
|
|
43
43
|
replay::DEFAULT_WORKFLOW_TYPE,
|
|
@@ -49,127 +49,155 @@ static PARENT_WF_TYPE: &str = "parent_wf";
|
|
|
49
49
|
static CHILD_WF_TYPE: &str = "child_wf";
|
|
50
50
|
const SIGNAME: &str = "SIGNAME";
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
#[workflow]
|
|
53
|
+
#[derive(Default)]
|
|
54
|
+
struct ChildWf;
|
|
55
|
+
|
|
56
|
+
#[workflow_methods]
|
|
57
|
+
impl ChildWf {
|
|
58
|
+
#[run(name = "child_wf")]
|
|
59
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
60
|
+
assert_eq!(
|
|
61
|
+
ctx.workflow_initial_info()
|
|
62
|
+
.parent_workflow_info
|
|
63
|
+
.as_ref()
|
|
64
|
+
.unwrap()
|
|
65
|
+
.workflow_id,
|
|
66
|
+
ctx.workflow_initial_info()
|
|
67
|
+
.root_workflow
|
|
68
|
+
.as_ref()
|
|
69
|
+
.unwrap()
|
|
70
|
+
.workflow_id
|
|
71
|
+
);
|
|
72
|
+
Ok(())
|
|
73
|
+
}
|
|
66
74
|
}
|
|
67
75
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
workflow_type: CHILD_WF_TYPE.to_owned(),
|
|
72
|
-
..Default::default()
|
|
73
|
-
});
|
|
76
|
+
#[workflow]
|
|
77
|
+
#[derive(Default)]
|
|
78
|
+
struct HappyParent;
|
|
74
79
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
#[workflow_methods]
|
|
81
|
+
impl HappyParent {
|
|
82
|
+
#[run(name = "parent_wf")]
|
|
83
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
84
|
+
let child = ctx.child_workflow(ChildWorkflowOptions {
|
|
85
|
+
workflow_id: "child-1".to_owned(),
|
|
86
|
+
workflow_type: CHILD_WF_TYPE.to_owned(),
|
|
87
|
+
..Default::default()
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
let started = child
|
|
91
|
+
.start()
|
|
92
|
+
.await
|
|
93
|
+
.into_started()
|
|
94
|
+
.expect("Child chould start OK");
|
|
95
|
+
match started.result().await.status {
|
|
96
|
+
Some(child_workflow_result::Status::Completed(Success { .. })) => Ok(()),
|
|
97
|
+
_ => Err(anyhow!("Unexpected child WF status").into()),
|
|
98
|
+
}
|
|
83
99
|
}
|
|
84
100
|
}
|
|
85
101
|
|
|
86
102
|
#[tokio::test]
|
|
87
103
|
async fn child_workflow_happy_path() {
|
|
88
104
|
let mut starter = CoreWfStarter::new("child-workflows");
|
|
89
|
-
starter
|
|
90
|
-
.worker_config
|
|
91
|
-
.task_types(WorkerTaskTypes::workflow_only());
|
|
105
|
+
starter.sdk_config.task_types = WorkerTaskTypes::workflow_only();
|
|
92
106
|
let mut worker = starter.worker().await;
|
|
93
107
|
|
|
94
|
-
worker.
|
|
95
|
-
worker.
|
|
108
|
+
worker.register_workflow::<HappyParent>();
|
|
109
|
+
worker.register_workflow::<ChildWf>();
|
|
96
110
|
|
|
111
|
+
let task_queue = starter.get_task_queue().to_owned();
|
|
97
112
|
worker
|
|
98
113
|
.submit_wf(
|
|
99
|
-
"parent".to_string(),
|
|
100
114
|
PARENT_WF_TYPE.to_owned(),
|
|
101
115
|
vec![],
|
|
102
|
-
|
|
116
|
+
WorkflowStartOptions::new(task_queue, "parent".to_string()).build(),
|
|
103
117
|
)
|
|
104
118
|
.await
|
|
105
119
|
.unwrap();
|
|
106
120
|
worker.run_until_done().await.unwrap();
|
|
107
121
|
}
|
|
108
122
|
|
|
123
|
+
#[workflow]
|
|
124
|
+
struct AbandonedChildBugReproParent {
|
|
125
|
+
barr: Arc<Barrier>,
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
#[workflow_methods(factory_only)]
|
|
129
|
+
impl AbandonedChildBugReproParent {
|
|
130
|
+
#[run(name = "parent_wf")]
|
|
131
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
132
|
+
let child = ctx.child_workflow(ChildWorkflowOptions {
|
|
133
|
+
workflow_id: "abandoned-child".to_owned(),
|
|
134
|
+
workflow_type: CHILD_WF_TYPE.to_owned(),
|
|
135
|
+
parent_close_policy: ParentClosePolicy::Abandon,
|
|
136
|
+
cancel_type: ChildWorkflowCancellationType::Abandon,
|
|
137
|
+
..Default::default()
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
let started = child
|
|
141
|
+
.start()
|
|
142
|
+
.await
|
|
143
|
+
.into_started()
|
|
144
|
+
.expect("Child chould start OK");
|
|
145
|
+
let barr = ctx.state(|wf| wf.barr.clone());
|
|
146
|
+
barr.wait().await;
|
|
147
|
+
ctx.cancelled().await;
|
|
148
|
+
started.cancel("Die reason!".to_string());
|
|
149
|
+
ctx.timer(Duration::from_secs(1)).await;
|
|
150
|
+
started.result().await;
|
|
151
|
+
Ok(())
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
#[workflow]
|
|
156
|
+
#[derive(Default)]
|
|
157
|
+
struct AbandonedChildBugReproChild;
|
|
158
|
+
|
|
159
|
+
#[workflow_methods]
|
|
160
|
+
impl AbandonedChildBugReproChild {
|
|
161
|
+
#[run(name = "child_wf")]
|
|
162
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
163
|
+
ctx.cancelled().await;
|
|
164
|
+
Err(WorkflowTermination::Cancelled)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
109
168
|
#[tokio::test]
|
|
110
169
|
async fn abandoned_child_bug_repro() {
|
|
111
170
|
let mut starter = CoreWfStarter::new("child-workflow-abandon-bug");
|
|
112
|
-
starter
|
|
113
|
-
.worker_config
|
|
114
|
-
.task_types(WorkerTaskTypes::workflow_only());
|
|
171
|
+
starter.sdk_config.task_types = WorkerTaskTypes::workflow_only();
|
|
115
172
|
let mut worker = starter.worker().await;
|
|
116
|
-
let barr: &'static Barrier = Box::leak(Box::new(Barrier::new(2)));
|
|
117
|
-
|
|
118
|
-
worker.register_wf(
|
|
119
|
-
PARENT_WF_TYPE.to_string(),
|
|
120
|
-
move |ctx: WfContext| async move {
|
|
121
|
-
let child = ctx.child_workflow(ChildWorkflowOptions {
|
|
122
|
-
workflow_id: "abandoned-child".to_owned(),
|
|
123
|
-
workflow_type: CHILD_WF_TYPE.to_owned(),
|
|
124
|
-
parent_close_policy: ParentClosePolicy::Abandon,
|
|
125
|
-
cancel_type: ChildWorkflowCancellationType::Abandon,
|
|
126
|
-
..Default::default()
|
|
127
|
-
});
|
|
128
173
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
.expect("Child chould start OK");
|
|
134
|
-
barr.wait().await;
|
|
135
|
-
// Wait for cancel signal
|
|
136
|
-
ctx.cancelled().await;
|
|
137
|
-
// Cancel the child immediately
|
|
138
|
-
started.cancel(&ctx, "Die reason!".to_string());
|
|
139
|
-
// Need to do something else, so we'll see the ChildWorkflowExecutionCanceled event
|
|
140
|
-
ctx.timer(Duration::from_secs(1)).await;
|
|
141
|
-
started.result().await;
|
|
142
|
-
Ok(().into())
|
|
143
|
-
},
|
|
144
|
-
);
|
|
145
|
-
worker.register_wf(CHILD_WF_TYPE.to_string(), |ctx: WfContext| async move {
|
|
146
|
-
ctx.cancelled().await;
|
|
147
|
-
Ok(WfExitValue::<()>::Cancelled)
|
|
174
|
+
let barr = Arc::new(Barrier::new(2));
|
|
175
|
+
let barr_clone = barr.clone();
|
|
176
|
+
worker.register_workflow_with_factory(move || AbandonedChildBugReproParent {
|
|
177
|
+
barr: barr_clone.clone(),
|
|
148
178
|
});
|
|
179
|
+
worker.register_workflow::<AbandonedChildBugReproChild>();
|
|
149
180
|
|
|
181
|
+
let task_queue = starter.get_task_queue().to_owned();
|
|
150
182
|
worker
|
|
151
|
-
.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
WorkflowOptions::default(),
|
|
183
|
+
.submit_workflow(
|
|
184
|
+
AbandonedChildBugReproParent::run,
|
|
185
|
+
(),
|
|
186
|
+
WorkflowStartOptions::new(task_queue, "parent-abandoner").build(),
|
|
156
187
|
)
|
|
157
188
|
.await
|
|
158
189
|
.unwrap();
|
|
159
190
|
let client = starter.get_client().await;
|
|
160
191
|
let canceller = async {
|
|
161
192
|
barr.wait().await;
|
|
162
|
-
client
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
None,
|
|
166
|
-
"die".to_string(),
|
|
167
|
-
None,
|
|
168
|
-
)
|
|
193
|
+
let parent_handle = client.get_workflow_handle::<UntypedWorkflow>("parent-abandoner");
|
|
194
|
+
parent_handle
|
|
195
|
+
.cancel(WorkflowCancelOptions::builder().reason("die").build())
|
|
169
196
|
.await
|
|
170
197
|
.unwrap();
|
|
171
|
-
client
|
|
172
|
-
|
|
198
|
+
let child_handle = client.get_workflow_handle::<UntypedWorkflow>("abandoned-child");
|
|
199
|
+
child_handle
|
|
200
|
+
.cancel(WorkflowCancelOptions::builder().reason("die").build())
|
|
173
201
|
.await
|
|
174
202
|
.unwrap();
|
|
175
203
|
};
|
|
@@ -179,65 +207,78 @@ async fn abandoned_child_bug_repro() {
|
|
|
179
207
|
tokio::join!(canceller, runner);
|
|
180
208
|
}
|
|
181
209
|
|
|
210
|
+
#[workflow]
|
|
211
|
+
struct AbandonedChildResolvesPostCancelParent {
|
|
212
|
+
barr: Arc<Barrier>,
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
#[workflow_methods(factory_only)]
|
|
216
|
+
impl AbandonedChildResolvesPostCancelParent {
|
|
217
|
+
#[run(name = "parent_wf")]
|
|
218
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
219
|
+
let child = ctx.child_workflow(ChildWorkflowOptions {
|
|
220
|
+
workflow_id: "abandoned-child-resolve-post-cancel".to_owned(),
|
|
221
|
+
workflow_type: CHILD_WF_TYPE.to_owned(),
|
|
222
|
+
parent_close_policy: ParentClosePolicy::Abandon,
|
|
223
|
+
cancel_type: ChildWorkflowCancellationType::Abandon,
|
|
224
|
+
..Default::default()
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
let started = child
|
|
228
|
+
.start()
|
|
229
|
+
.await
|
|
230
|
+
.into_started()
|
|
231
|
+
.expect("Child chould start OK");
|
|
232
|
+
let barr = ctx.state(|wf| wf.barr.clone());
|
|
233
|
+
barr.wait().await;
|
|
234
|
+
ctx.cancelled().await;
|
|
235
|
+
started.cancel("Die reason".to_string());
|
|
236
|
+
ctx.timer(Duration::from_secs(1)).await;
|
|
237
|
+
started.result().await;
|
|
238
|
+
Ok(())
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
#[workflow]
|
|
243
|
+
#[derive(Default)]
|
|
244
|
+
struct AbandonedChildResolvesPostCancelChild;
|
|
245
|
+
|
|
246
|
+
#[workflow_methods]
|
|
247
|
+
impl AbandonedChildResolvesPostCancelChild {
|
|
248
|
+
#[run(name = "child_wf")]
|
|
249
|
+
async fn run(_ctx: &mut WorkflowContext<Self>) -> WorkflowResult<String> {
|
|
250
|
+
Ok("I'm done".to_string())
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
182
254
|
#[tokio::test]
|
|
183
255
|
async fn abandoned_child_resolves_post_cancel() {
|
|
184
256
|
let mut starter = CoreWfStarter::new("child-workflow-resolves-post-cancel");
|
|
185
|
-
starter
|
|
186
|
-
.worker_config
|
|
187
|
-
.task_types(WorkerTaskTypes::workflow_only());
|
|
257
|
+
starter.sdk_config.task_types = WorkerTaskTypes::workflow_only();
|
|
188
258
|
let mut worker = starter.worker().await;
|
|
189
|
-
let barr: &'static Barrier = Box::leak(Box::new(Barrier::new(2)));
|
|
190
|
-
|
|
191
|
-
worker.register_wf(
|
|
192
|
-
PARENT_WF_TYPE.to_string(),
|
|
193
|
-
move |ctx: WfContext| async move {
|
|
194
|
-
let child = ctx.child_workflow(ChildWorkflowOptions {
|
|
195
|
-
workflow_id: "abandoned-child-resolve-post-cancel".to_owned(),
|
|
196
|
-
workflow_type: CHILD_WF_TYPE.to_owned(),
|
|
197
|
-
parent_close_policy: ParentClosePolicy::Abandon,
|
|
198
|
-
cancel_type: ChildWorkflowCancellationType::Abandon,
|
|
199
|
-
..Default::default()
|
|
200
|
-
});
|
|
201
259
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
.expect("Child chould start OK");
|
|
207
|
-
barr.wait().await;
|
|
208
|
-
// Wait for cancel signal
|
|
209
|
-
ctx.cancelled().await;
|
|
210
|
-
// Cancel the child immediately
|
|
211
|
-
started.cancel(&ctx, "Die reason".to_string());
|
|
212
|
-
// Need to do something else, so we will see the child completing
|
|
213
|
-
ctx.timer(Duration::from_secs(1)).await;
|
|
214
|
-
started.result().await;
|
|
215
|
-
Ok(().into())
|
|
216
|
-
},
|
|
217
|
-
);
|
|
218
|
-
worker.register_wf(CHILD_WF_TYPE.to_string(), |_: WfContext| async move {
|
|
219
|
-
Ok("I'm done".into())
|
|
260
|
+
let barr = Arc::new(Barrier::new(2));
|
|
261
|
+
let barr_clone = barr.clone();
|
|
262
|
+
worker.register_workflow_with_factory(move || AbandonedChildResolvesPostCancelParent {
|
|
263
|
+
barr: barr_clone.clone(),
|
|
220
264
|
});
|
|
265
|
+
worker.register_workflow::<AbandonedChildResolvesPostCancelChild>();
|
|
221
266
|
|
|
267
|
+
let task_queue = starter.get_task_queue().to_owned();
|
|
222
268
|
worker
|
|
223
|
-
.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
WorkflowOptions::default(),
|
|
269
|
+
.submit_workflow(
|
|
270
|
+
AbandonedChildResolvesPostCancelParent::run,
|
|
271
|
+
(),
|
|
272
|
+
WorkflowStartOptions::new(task_queue, "parent-abandoner-resolving").build(),
|
|
228
273
|
)
|
|
229
274
|
.await
|
|
230
275
|
.unwrap();
|
|
231
276
|
let client = starter.get_client().await;
|
|
232
277
|
let canceller = async {
|
|
233
278
|
barr.wait().await;
|
|
234
|
-
client
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
None,
|
|
238
|
-
"die".to_string(),
|
|
239
|
-
None,
|
|
240
|
-
)
|
|
279
|
+
let handle = client.get_workflow_handle::<UntypedWorkflow>("parent-abandoner-resolving");
|
|
280
|
+
handle
|
|
281
|
+
.cancel(WorkflowCancelOptions::builder().reason("die").build())
|
|
241
282
|
.await
|
|
242
283
|
.unwrap();
|
|
243
284
|
};
|
|
@@ -247,16 +288,14 @@ async fn abandoned_child_resolves_post_cancel() {
|
|
|
247
288
|
tokio::join!(canceller, runner);
|
|
248
289
|
}
|
|
249
290
|
|
|
250
|
-
#[
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
let mut starter = CoreWfStarter::new(wf_name);
|
|
254
|
-
starter
|
|
255
|
-
.worker_config
|
|
256
|
-
.task_types(WorkerTaskTypes::workflow_only());
|
|
257
|
-
let mut worker = starter.worker().await;
|
|
291
|
+
#[workflow]
|
|
292
|
+
#[derive(Default)]
|
|
293
|
+
struct CancelledChildGetsReasonParent;
|
|
258
294
|
|
|
259
|
-
|
|
295
|
+
#[workflow_methods]
|
|
296
|
+
impl CancelledChildGetsReasonParent {
|
|
297
|
+
#[run]
|
|
298
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
260
299
|
let child = ctx.child_workflow(ChildWorkflowOptions {
|
|
261
300
|
workflow_id: format!("{}-child", ctx.task_queue()),
|
|
262
301
|
workflow_type: CHILD_WF_TYPE.to_owned(),
|
|
@@ -265,44 +304,63 @@ async fn cancelled_child_gets_reason() {
|
|
|
265
304
|
});
|
|
266
305
|
|
|
267
306
|
let started = child
|
|
268
|
-
.start(
|
|
307
|
+
.start()
|
|
269
308
|
.await
|
|
270
309
|
.into_started()
|
|
271
310
|
.expect("Child chould start OK");
|
|
272
|
-
|
|
273
|
-
started.cancel(&ctx, "Die reason".to_string());
|
|
311
|
+
started.cancel("Die reason".to_string());
|
|
274
312
|
let r = started.result().await;
|
|
275
313
|
let out = assert_matches!(r.status,
|
|
276
|
-
|
|
314
|
+
Some(child_workflow_result::Status::Completed(reason)) => reason);
|
|
277
315
|
assert_eq!(out.result.unwrap(), "Die reason".as_json_payload().unwrap());
|
|
278
|
-
Ok(()
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
let r = c.cancelled().await;
|
|
282
|
-
Ok(r.into())
|
|
283
|
-
});
|
|
316
|
+
Ok(())
|
|
317
|
+
}
|
|
318
|
+
}
|
|
284
319
|
|
|
285
|
-
|
|
286
|
-
|
|
320
|
+
#[workflow]
|
|
321
|
+
#[derive(Default)]
|
|
322
|
+
struct CancelledChildGetsReasonChild;
|
|
323
|
+
|
|
324
|
+
#[workflow_methods]
|
|
325
|
+
impl CancelledChildGetsReasonChild {
|
|
326
|
+
#[run(name = "child_wf")]
|
|
327
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<String> {
|
|
328
|
+
let r = ctx.cancelled().await;
|
|
329
|
+
Ok(r)
|
|
330
|
+
}
|
|
287
331
|
}
|
|
288
332
|
|
|
289
|
-
#[rstest::rstest]
|
|
290
|
-
#[case::signal_then_result(true)]
|
|
291
|
-
#[case::signal_and_result_concurrent(false)]
|
|
292
333
|
#[tokio::test]
|
|
293
|
-
async fn
|
|
294
|
-
let
|
|
295
|
-
let
|
|
296
|
-
|
|
297
|
-
let
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
[ResponseType::AllHistory],
|
|
302
|
-
mock,
|
|
303
|
-
));
|
|
334
|
+
async fn cancelled_child_gets_reason() {
|
|
335
|
+
let wf_name = "cancelled-child-gets-reason";
|
|
336
|
+
let mut starter = CoreWfStarter::new(wf_name);
|
|
337
|
+
starter.sdk_config.task_types = WorkerTaskTypes::workflow_only();
|
|
338
|
+
let mut worker = starter.worker().await;
|
|
339
|
+
|
|
340
|
+
worker.register_workflow::<CancelledChildGetsReasonParent>();
|
|
341
|
+
worker.register_workflow::<CancelledChildGetsReasonChild>();
|
|
304
342
|
|
|
305
|
-
let
|
|
343
|
+
let task_queue = starter.get_task_queue().to_owned();
|
|
344
|
+
worker
|
|
345
|
+
.submit_workflow(
|
|
346
|
+
CancelledChildGetsReasonParent::run,
|
|
347
|
+
(),
|
|
348
|
+
WorkflowStartOptions::new(task_queue.clone(), task_queue).build(),
|
|
349
|
+
)
|
|
350
|
+
.await
|
|
351
|
+
.unwrap();
|
|
352
|
+
worker.run_until_done().await.unwrap();
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
#[workflow]
|
|
356
|
+
struct SignalChildWorkflowWf {
|
|
357
|
+
serial: bool,
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
#[workflow_methods(factory_only)]
|
|
361
|
+
impl SignalChildWorkflowWf {
|
|
362
|
+
#[run(name = DEFAULT_WORKFLOW_TYPE)]
|
|
363
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
306
364
|
let child = ctx.child_workflow(ChildWorkflowOptions {
|
|
307
365
|
workflow_id: "child-id-1".to_string(),
|
|
308
366
|
workflow_type: "child".to_string(),
|
|
@@ -310,65 +368,91 @@ async fn signal_child_workflow(#[case] serial: bool) {
|
|
|
310
368
|
});
|
|
311
369
|
|
|
312
370
|
let start_res = child
|
|
313
|
-
.start(
|
|
371
|
+
.start()
|
|
314
372
|
.await
|
|
315
373
|
.into_started()
|
|
316
374
|
.expect("Child should get started");
|
|
375
|
+
let serial = ctx.state(|wf| wf.serial);
|
|
317
376
|
let (sigres, res) = if serial {
|
|
318
|
-
let sigres = start_res.signal(
|
|
377
|
+
let sigres = start_res.signal(Signal::new(SIGNAME, [b"Hi!"])).await;
|
|
319
378
|
let res = start_res.result().await;
|
|
320
379
|
(sigres, res)
|
|
321
380
|
} else {
|
|
322
|
-
let sigfut = start_res.signal(
|
|
381
|
+
let sigfut = start_res.signal(Signal::new(SIGNAME, [b"Hi!"]));
|
|
323
382
|
let resfut = start_res.result();
|
|
324
383
|
join!(sigfut, resfut)
|
|
325
384
|
};
|
|
326
385
|
sigres.expect("signal result is ok");
|
|
327
386
|
res.status.expect("child wf result is ok");
|
|
328
|
-
Ok(()
|
|
329
|
-
}
|
|
387
|
+
Ok(())
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
#[rstest::rstest]
|
|
392
|
+
#[case::signal_then_result(true)]
|
|
393
|
+
#[case::signal_and_result_concurrent(false)]
|
|
394
|
+
#[tokio::test]
|
|
395
|
+
async fn signal_child_workflow(#[case] serial: bool) {
|
|
396
|
+
let wf_id = "fakeid";
|
|
397
|
+
let wf_type = DEFAULT_WORKFLOW_TYPE;
|
|
398
|
+
let t = canned_histories::single_child_workflow_signaled("child-id-1", SIGNAME);
|
|
399
|
+
let mock = mock_worker_client();
|
|
400
|
+
let mut worker = mock_sdk(MockPollCfg::from_resp_batches(
|
|
401
|
+
wf_id,
|
|
402
|
+
t,
|
|
403
|
+
[ResponseType::AllHistory],
|
|
404
|
+
mock,
|
|
405
|
+
));
|
|
330
406
|
|
|
331
|
-
worker.
|
|
407
|
+
worker.register_workflow_with_factory(move || SignalChildWorkflowWf { serial });
|
|
408
|
+
let task_queue = worker.inner_mut().task_queue().to_owned();
|
|
332
409
|
worker
|
|
333
410
|
.submit_wf(
|
|
334
|
-
wf_id.to_owned(),
|
|
335
411
|
wf_type.to_owned(),
|
|
336
412
|
vec![],
|
|
337
|
-
|
|
413
|
+
WorkflowStartOptions::new(task_queue, wf_id.to_owned()).build(),
|
|
338
414
|
)
|
|
339
415
|
.await
|
|
340
416
|
.unwrap();
|
|
341
417
|
worker.run_until_done().await.unwrap();
|
|
342
418
|
}
|
|
343
419
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
workflow_type: "child".to_string(),
|
|
348
|
-
cancel_type: ChildWorkflowCancellationType::WaitCancellationCompleted,
|
|
349
|
-
..Default::default()
|
|
350
|
-
});
|
|
420
|
+
#[workflow]
|
|
421
|
+
#[derive(Default)]
|
|
422
|
+
struct ParentCancelsChildWf;
|
|
351
423
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
.
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
424
|
+
#[workflow_methods]
|
|
425
|
+
impl ParentCancelsChildWf {
|
|
426
|
+
#[run(name = DEFAULT_WORKFLOW_TYPE)]
|
|
427
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
428
|
+
let child = ctx.child_workflow(ChildWorkflowOptions {
|
|
429
|
+
workflow_id: "child-id-1".to_string(),
|
|
430
|
+
workflow_type: "child".to_string(),
|
|
431
|
+
cancel_type: ChildWorkflowCancellationType::WaitCancellationCompleted,
|
|
432
|
+
..Default::default()
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
let start_res = child
|
|
436
|
+
.start()
|
|
437
|
+
.await
|
|
438
|
+
.into_started()
|
|
439
|
+
.expect("Child should get started");
|
|
440
|
+
start_res.cancel("cancel reason".to_string());
|
|
441
|
+
let stat = start_res
|
|
442
|
+
.result()
|
|
443
|
+
.await
|
|
444
|
+
.status
|
|
445
|
+
.expect("child wf result is ok");
|
|
446
|
+
assert_matches!(stat, child_workflow_result::Status::Cancelled(_));
|
|
447
|
+
Ok(())
|
|
448
|
+
}
|
|
365
449
|
}
|
|
366
450
|
|
|
367
451
|
#[tokio::test]
|
|
368
452
|
async fn cancel_child_workflow() {
|
|
369
453
|
let t = canned_histories::single_child_workflow_cancelled("child-id-1");
|
|
370
454
|
let mut worker = build_fake_sdk(MockPollCfg::from_resps(t, [ResponseType::AllHistory]));
|
|
371
|
-
worker.
|
|
455
|
+
worker.register_workflow::<ParentCancelsChildWf>();
|
|
372
456
|
worker.run().await.unwrap();
|
|
373
457
|
}
|
|
374
458
|
|
|
@@ -488,6 +572,29 @@ async fn cancel_already_complete_child_ignored() {
|
|
|
488
572
|
.unwrap();
|
|
489
573
|
}
|
|
490
574
|
|
|
575
|
+
#[workflow]
|
|
576
|
+
struct PassChildWorkflowSummaryToMetadata {
|
|
577
|
+
child_wf_id: String,
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
#[workflow_methods(factory_only)]
|
|
581
|
+
impl PassChildWorkflowSummaryToMetadata {
|
|
582
|
+
#[run(name = DEFAULT_WORKFLOW_TYPE)]
|
|
583
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
584
|
+
let child_wf_id = ctx.state(|wf| wf.child_wf_id.clone());
|
|
585
|
+
ctx.child_workflow(ChildWorkflowOptions {
|
|
586
|
+
workflow_id: child_wf_id,
|
|
587
|
+
workflow_type: "child".to_string(),
|
|
588
|
+
static_summary: Some("child summary".to_string()),
|
|
589
|
+
static_details: Some("child details".to_string()),
|
|
590
|
+
..Default::default()
|
|
591
|
+
})
|
|
592
|
+
.start()
|
|
593
|
+
.await;
|
|
594
|
+
Ok(())
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
491
598
|
#[tokio::test]
|
|
492
599
|
async fn pass_child_workflow_summary_to_metadata() {
|
|
493
600
|
let wf_id = "1";
|
|
@@ -518,24 +625,16 @@ async fn pass_child_workflow_summary_to_metadata() {
|
|
|
518
625
|
});
|
|
519
626
|
|
|
520
627
|
let mut worker = mock_sdk_cfg(mock_cfg, |_| {});
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
workflow_type: "child".to_string(),
|
|
525
|
-
static_summary: Some("child summary".to_string()),
|
|
526
|
-
static_details: Some("child details".to_string()),
|
|
527
|
-
..Default::default()
|
|
528
|
-
})
|
|
529
|
-
.start(&ctx)
|
|
530
|
-
.await;
|
|
531
|
-
Ok(().into())
|
|
628
|
+
let child_wf_id = wf_id.to_string();
|
|
629
|
+
worker.register_workflow_with_factory(move || PassChildWorkflowSummaryToMetadata {
|
|
630
|
+
child_wf_id: child_wf_id.clone(),
|
|
532
631
|
});
|
|
632
|
+
let task_queue = worker.inner_mut().task_queue().to_owned();
|
|
533
633
|
worker
|
|
534
634
|
.submit_wf(
|
|
535
|
-
wf_id.to_owned(),
|
|
536
635
|
wf_type.to_owned(),
|
|
537
636
|
vec![],
|
|
538
|
-
|
|
637
|
+
WorkflowStartOptions::new(task_queue, wf_id.to_owned()).build(),
|
|
539
638
|
)
|
|
540
639
|
.await
|
|
541
640
|
.unwrap();
|
|
@@ -563,38 +662,46 @@ impl Expectation {
|
|
|
563
662
|
#[fixture]
|
|
564
663
|
fn child_workflow_happy_hist() -> MockPollCfg {
|
|
565
664
|
let mut t = canned_histories::single_child_workflow("child-id-1");
|
|
566
|
-
t.set_wf_input(
|
|
665
|
+
t.set_wf_input((Expectation::Success as u8).as_json_payload().unwrap());
|
|
567
666
|
MockPollCfg::from_hist_builder(t)
|
|
568
667
|
}
|
|
569
668
|
|
|
570
669
|
#[fixture]
|
|
571
670
|
fn child_workflow_fail_hist() -> MockPollCfg {
|
|
572
671
|
let mut t = canned_histories::single_child_workflow_fail("child-id-1");
|
|
573
|
-
t.set_wf_input(
|
|
672
|
+
t.set_wf_input((Expectation::Failure as u8).as_json_payload().unwrap());
|
|
574
673
|
MockPollCfg::from_hist_builder(t)
|
|
575
674
|
}
|
|
576
675
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
workflow_id: "child-id-1".to_string(),
|
|
581
|
-
workflow_type: "child".to_string(),
|
|
582
|
-
..Default::default()
|
|
583
|
-
});
|
|
676
|
+
#[workflow]
|
|
677
|
+
#[derive(Default)]
|
|
678
|
+
struct ParentWf;
|
|
584
679
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
680
|
+
#[workflow_methods]
|
|
681
|
+
impl ParentWf {
|
|
682
|
+
#[run(name = DEFAULT_WORKFLOW_TYPE)]
|
|
683
|
+
async fn run(ctx: &mut WorkflowContext<Self>, expectation_u8: u8) -> WorkflowResult<()> {
|
|
684
|
+
let expectation = Expectation::try_from_u8(expectation_u8).unwrap();
|
|
685
|
+
let child = ctx.child_workflow(ChildWorkflowOptions {
|
|
686
|
+
workflow_id: "child-id-1".to_string(),
|
|
687
|
+
workflow_type: "child".to_string(),
|
|
688
|
+
..Default::default()
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
let start_res = child.start().await;
|
|
692
|
+
match (expectation, &start_res.status) {
|
|
693
|
+
(Expectation::Success | Expectation::Failure, StartStatus::Succeeded(_)) => {}
|
|
694
|
+
(Expectation::StartFailure, StartStatus::Failed(_)) => return Ok(()),
|
|
695
|
+
_ => return Err(anyhow!("Unexpected start status").into()),
|
|
696
|
+
};
|
|
697
|
+
match (
|
|
698
|
+
expectation,
|
|
699
|
+
start_res.into_started().unwrap().result().await.status,
|
|
700
|
+
) {
|
|
701
|
+
(Expectation::Success, Some(child_workflow_result::Status::Completed(_))) => Ok(()),
|
|
702
|
+
(Expectation::Failure, _) => Ok(()),
|
|
703
|
+
_ => Err(anyhow!("Unexpected child WF status").into()),
|
|
704
|
+
}
|
|
598
705
|
}
|
|
599
706
|
}
|
|
600
707
|
|
|
@@ -627,7 +734,7 @@ async fn single_child_workflow_until_completion(mut mock_cfg: MockPollCfg) {
|
|
|
627
734
|
});
|
|
628
735
|
|
|
629
736
|
let mut worker = build_fake_sdk(mock_cfg);
|
|
630
|
-
worker.
|
|
737
|
+
worker.register_workflow::<ParentWf>();
|
|
631
738
|
worker.run().await.unwrap();
|
|
632
739
|
}
|
|
633
740
|
|
|
@@ -636,7 +743,7 @@ async fn single_child_workflow_start_fail() {
|
|
|
636
743
|
let child_wf_id = "child-id-1";
|
|
637
744
|
let mut t = TestHistoryBuilder::default();
|
|
638
745
|
t.add_by_type(EventType::WorkflowExecutionStarted);
|
|
639
|
-
t.set_wf_input(
|
|
746
|
+
t.set_wf_input((Expectation::StartFailure as u8).as_json_payload().unwrap());
|
|
640
747
|
t.add_full_wf_task();
|
|
641
748
|
let initiated_event_id = t.add(StartChildWorkflowExecutionInitiatedEventAttributes {
|
|
642
749
|
workflow_id: child_wf_id.to_owned(),
|
|
@@ -672,22 +779,30 @@ async fn single_child_workflow_start_fail() {
|
|
|
672
779
|
});
|
|
673
780
|
|
|
674
781
|
let mut worker = build_fake_sdk(mock_cfg);
|
|
675
|
-
worker.
|
|
782
|
+
worker.register_workflow::<ParentWf>();
|
|
676
783
|
worker.run().await.unwrap();
|
|
677
784
|
}
|
|
678
785
|
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
786
|
+
#[workflow]
|
|
787
|
+
#[derive(Default)]
|
|
788
|
+
struct CancelBeforeSendWf;
|
|
789
|
+
|
|
790
|
+
#[workflow_methods]
|
|
791
|
+
impl CancelBeforeSendWf {
|
|
792
|
+
#[run(name = DEFAULT_WORKFLOW_TYPE)]
|
|
793
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
794
|
+
let workflow_id = "child-id-1";
|
|
795
|
+
let child = ctx.child_workflow(ChildWorkflowOptions {
|
|
796
|
+
workflow_id: workflow_id.to_string(),
|
|
797
|
+
workflow_type: "child".to_string(),
|
|
798
|
+
..Default::default()
|
|
799
|
+
});
|
|
800
|
+
let start = child.start();
|
|
801
|
+
start.cancel();
|
|
802
|
+
match start.await.status {
|
|
803
|
+
StartStatus::Cancelled(_) => Ok(()),
|
|
804
|
+
_ => Err(anyhow!("Unexpected start status").into()),
|
|
805
|
+
}
|
|
691
806
|
}
|
|
692
807
|
}
|
|
693
808
|
|
|
@@ -701,8 +816,6 @@ async fn single_child_workflow_cancel_before_sent() {
|
|
|
701
816
|
let mut mock_cfg = MockPollCfg::from_hist_builder(t);
|
|
702
817
|
mock_cfg.completion_asserts_from_expectations(|mut asserts| {
|
|
703
818
|
asserts.then(move |wft| {
|
|
704
|
-
// Workflow starts and cancels the child workflow, no commands should be sent besides
|
|
705
|
-
// workflow completion
|
|
706
819
|
assert_eq!(wft.commands.len(), 1);
|
|
707
820
|
assert_matches!(
|
|
708
821
|
wft.commands[0].command_type(),
|
|
@@ -712,6 +825,6 @@ async fn single_child_workflow_cancel_before_sent() {
|
|
|
712
825
|
});
|
|
713
826
|
|
|
714
827
|
let mut worker = build_fake_sdk(mock_cfg);
|
|
715
|
-
worker.
|
|
828
|
+
worker.register_workflow::<CancelBeforeSendWf>();
|
|
716
829
|
worker.run().await.unwrap();
|
|
717
830
|
}
|