@temporalio/core-bridge 1.15.0 → 1.16.1
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 +172 -70
- package/lib/native.d.ts +1 -1
- package/package.json +2 -2
- 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 +41 -30
- package/sdk-core/Cargo.toml +3 -0
- package/sdk-core/README.md +15 -9
- 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} +280 -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} +1 -1
- package/sdk-core/crates/client/src/workflow_handle.rs +826 -0
- package/sdk-core/crates/common/Cargo.toml +61 -2
- 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/Makefile +2 -1
- package/sdk-core/crates/common/protos/api_upstream/buf.yaml +0 -3
- 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 +1166 -770
- package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv3.yaml +1243 -750
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/deployment/v1/message.proto +2 -2
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/workflow.proto +4 -3
- 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 +4 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/namespace/v1/message.proto +6 -0
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/nexus/v1/message.proto +16 -1
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +64 -6
- package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +88 -33
- package/sdk-core/crates/common/protos/local/temporal/sdk/core/nexus/nexus.proto +4 -2
- package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +4 -0
- package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +5 -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 +3 -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 +122 -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 +5 -7
- package/sdk-core/crates/common/src/telemetry/metrics/core.rs +125 -0
- package/sdk-core/crates/common/src/telemetry/metrics.rs +268 -223
- 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 +264 -4
- package/sdk-core/crates/common/src/worker.rs +68 -603
- 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 +757 -442
- package/sdk-core/crates/sdk/src/workflow_context/options.rs +45 -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 +57 -64
- package/sdk-core/crates/sdk-core/benches/workflow_replay_bench.rs +41 -35
- 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 +13 -15
- 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 +493 -26
- package/sdk-core/crates/sdk-core/src/core_tests/workflow_tasks.rs +4 -8
- package/sdk-core/crates/sdk-core/src/ephemeral_server/mod.rs +7 -7
- package/sdk-core/crates/sdk-core/src/histfetch.rs +20 -10
- package/sdk-core/crates/sdk-core/src/lib.rs +41 -111
- package/sdk-core/crates/sdk-core/src/pollers/mod.rs +4 -9
- package/sdk-core/crates/sdk-core/src/pollers/poll_buffer.rs +118 -19
- 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 +179 -196
- package/sdk-core/crates/sdk-core/src/telemetry/mod.rs +3 -280
- package/sdk-core/crates/sdk-core/src/test_help/integ_helpers.rs +6 -9
- package/sdk-core/crates/sdk-core/src/test_help/unit_helpers.rs +3 -6
- 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 +9 -5
- package/sdk-core/crates/sdk-core/src/worker/client.rs +103 -81
- package/sdk-core/crates/sdk-core/src/worker/heartbeat.rs +7 -11
- package/sdk-core/crates/sdk-core/src/worker/mod.rs +1124 -229
- package/sdk-core/crates/sdk-core/src/worker/nexus.rs +145 -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 +13 -13
- package/sdk-core/crates/sdk-core/src/worker/tuner.rs +28 -8
- package/sdk-core/crates/sdk-core/src/worker/workflow/driven_workflow.rs +9 -3
- 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 +19 -4
- package/sdk-core/crates/sdk-core/src/worker/workflow/managed_run.rs +14 -18
- package/sdk-core/crates/sdk-core/src/worker/workflow/mod.rs +4 -6
- 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 +241 -196
- package/sdk-core/crates/sdk-core/tests/common/workflows.rs +41 -28
- package/sdk-core/crates/sdk-core/tests/global_metric_tests.rs +3 -5
- package/sdk-core/crates/sdk-core/tests/heavy_tests/fuzzy_workflow.rs +73 -64
- package/sdk-core/crates/sdk-core/tests/heavy_tests.rs +298 -252
- 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 +16 -12
- package/sdk-core/crates/sdk-core/tests/integ_tests/heartbeat_tests.rs +48 -40
- package/sdk-core/crates/sdk-core/tests/integ_tests/metrics_tests.rs +327 -255
- 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 +147 -126
- 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 -453
- 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 +360 -231
- package/sdk-core/crates/sdk-core/tests/integ_tests/worker_tests.rs +248 -185
- package/sdk-core/crates/sdk-core/tests/integ_tests/worker_versioning_tests.rs +52 -43
- 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 +428 -315
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +82 -56
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +56 -28
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +364 -243
- 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 +101 -42
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +243 -147
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/eager.rs +98 -28
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +1475 -1036
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +73 -41
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +397 -238
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/patches.rs +414 -189
- 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 +154 -137
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/signals.rs +183 -105
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +85 -38
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/timers.rs +142 -40
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +73 -54
- package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests.rs +363 -226
- package/sdk-core/crates/sdk-core/tests/main.rs +17 -15
- package/sdk-core/crates/sdk-core/tests/manual_tests.rs +207 -152
- package/sdk-core/crates/sdk-core/tests/shared_tests/mod.rs +65 -34
- 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 +7 -1
- package/sdk-core/crates/sdk-core-c-bridge/include/temporal-sdk-core-c-bridge.h +14 -14
- package/sdk-core/crates/sdk-core-c-bridge/src/client.rs +83 -74
- package/sdk-core/crates/sdk-core-c-bridge/src/metric.rs +9 -14
- package/sdk-core/crates/sdk-core-c-bridge/src/runtime.rs +1 -2
- package/sdk-core/crates/sdk-core-c-bridge/src/tests/context.rs +13 -13
- package/sdk-core/crates/sdk-core-c-bridge/src/tests/mod.rs +6 -6
- package/sdk-core/crates/sdk-core-c-bridge/src/tests/utils.rs +3 -4
- package/sdk-core/crates/sdk-core-c-bridge/src/worker.rs +62 -75
- package/sdk-core/rustfmt.toml +2 -1
- package/src/client.rs +205 -318
- package/src/metrics.rs +22 -30
- package/src/runtime.rs +4 -5
- package/src/worker.rs +16 -19
- package/ts/native.ts +1 -1
- 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/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,123 +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.
|
|
105
|
+
starter.sdk_config.task_types = WorkerTaskTypes::workflow_only();
|
|
90
106
|
let mut worker = starter.worker().await;
|
|
91
107
|
|
|
92
|
-
worker.
|
|
93
|
-
worker.
|
|
108
|
+
worker.register_workflow::<HappyParent>();
|
|
109
|
+
worker.register_workflow::<ChildWf>();
|
|
94
110
|
|
|
111
|
+
let task_queue = starter.get_task_queue().to_owned();
|
|
95
112
|
worker
|
|
96
113
|
.submit_wf(
|
|
97
|
-
"parent".to_string(),
|
|
98
114
|
PARENT_WF_TYPE.to_owned(),
|
|
99
115
|
vec![],
|
|
100
|
-
|
|
116
|
+
WorkflowStartOptions::new(task_queue, "parent".to_string()).build(),
|
|
101
117
|
)
|
|
102
118
|
.await
|
|
103
119
|
.unwrap();
|
|
104
120
|
worker.run_until_done().await.unwrap();
|
|
105
121
|
}
|
|
106
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
|
+
|
|
107
168
|
#[tokio::test]
|
|
108
169
|
async fn abandoned_child_bug_repro() {
|
|
109
170
|
let mut starter = CoreWfStarter::new("child-workflow-abandon-bug");
|
|
110
|
-
starter.
|
|
171
|
+
starter.sdk_config.task_types = WorkerTaskTypes::workflow_only();
|
|
111
172
|
let mut worker = starter.worker().await;
|
|
112
|
-
let barr: &'static Barrier = Box::leak(Box::new(Barrier::new(2)));
|
|
113
|
-
|
|
114
|
-
worker.register_wf(
|
|
115
|
-
PARENT_WF_TYPE.to_string(),
|
|
116
|
-
move |ctx: WfContext| async move {
|
|
117
|
-
let child = ctx.child_workflow(ChildWorkflowOptions {
|
|
118
|
-
workflow_id: "abandoned-child".to_owned(),
|
|
119
|
-
workflow_type: CHILD_WF_TYPE.to_owned(),
|
|
120
|
-
parent_close_policy: ParentClosePolicy::Abandon,
|
|
121
|
-
cancel_type: ChildWorkflowCancellationType::Abandon,
|
|
122
|
-
..Default::default()
|
|
123
|
-
});
|
|
124
173
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
.expect("Child chould start OK");
|
|
130
|
-
barr.wait().await;
|
|
131
|
-
// Wait for cancel signal
|
|
132
|
-
ctx.cancelled().await;
|
|
133
|
-
// Cancel the child immediately
|
|
134
|
-
started.cancel(&ctx, "Die reason!".to_string());
|
|
135
|
-
// Need to do something else, so we'll see the ChildWorkflowExecutionCanceled event
|
|
136
|
-
ctx.timer(Duration::from_secs(1)).await;
|
|
137
|
-
started.result().await;
|
|
138
|
-
Ok(().into())
|
|
139
|
-
},
|
|
140
|
-
);
|
|
141
|
-
worker.register_wf(CHILD_WF_TYPE.to_string(), |ctx: WfContext| async move {
|
|
142
|
-
ctx.cancelled().await;
|
|
143
|
-
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(),
|
|
144
178
|
});
|
|
179
|
+
worker.register_workflow::<AbandonedChildBugReproChild>();
|
|
145
180
|
|
|
181
|
+
let task_queue = starter.get_task_queue().to_owned();
|
|
146
182
|
worker
|
|
147
|
-
.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
WorkflowOptions::default(),
|
|
183
|
+
.submit_workflow(
|
|
184
|
+
AbandonedChildBugReproParent::run,
|
|
185
|
+
(),
|
|
186
|
+
WorkflowStartOptions::new(task_queue, "parent-abandoner").build(),
|
|
152
187
|
)
|
|
153
188
|
.await
|
|
154
189
|
.unwrap();
|
|
155
190
|
let client = starter.get_client().await;
|
|
156
191
|
let canceller = async {
|
|
157
192
|
barr.wait().await;
|
|
158
|
-
client
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
None,
|
|
162
|
-
"die".to_string(),
|
|
163
|
-
None,
|
|
164
|
-
)
|
|
193
|
+
let parent_handle = client.get_workflow_handle::<UntypedWorkflow>("parent-abandoner");
|
|
194
|
+
parent_handle
|
|
195
|
+
.cancel(WorkflowCancelOptions::builder().reason("die").build())
|
|
165
196
|
.await
|
|
166
197
|
.unwrap();
|
|
167
|
-
client
|
|
168
|
-
|
|
198
|
+
let child_handle = client.get_workflow_handle::<UntypedWorkflow>("abandoned-child");
|
|
199
|
+
child_handle
|
|
200
|
+
.cancel(WorkflowCancelOptions::builder().reason("die").build())
|
|
169
201
|
.await
|
|
170
202
|
.unwrap();
|
|
171
203
|
};
|
|
@@ -175,63 +207,78 @@ async fn abandoned_child_bug_repro() {
|
|
|
175
207
|
tokio::join!(canceller, runner);
|
|
176
208
|
}
|
|
177
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
|
+
|
|
178
254
|
#[tokio::test]
|
|
179
255
|
async fn abandoned_child_resolves_post_cancel() {
|
|
180
256
|
let mut starter = CoreWfStarter::new("child-workflow-resolves-post-cancel");
|
|
181
|
-
starter.
|
|
257
|
+
starter.sdk_config.task_types = WorkerTaskTypes::workflow_only();
|
|
182
258
|
let mut worker = starter.worker().await;
|
|
183
|
-
let barr: &'static Barrier = Box::leak(Box::new(Barrier::new(2)));
|
|
184
|
-
|
|
185
|
-
worker.register_wf(
|
|
186
|
-
PARENT_WF_TYPE.to_string(),
|
|
187
|
-
move |ctx: WfContext| async move {
|
|
188
|
-
let child = ctx.child_workflow(ChildWorkflowOptions {
|
|
189
|
-
workflow_id: "abandoned-child-resolve-post-cancel".to_owned(),
|
|
190
|
-
workflow_type: CHILD_WF_TYPE.to_owned(),
|
|
191
|
-
parent_close_policy: ParentClosePolicy::Abandon,
|
|
192
|
-
cancel_type: ChildWorkflowCancellationType::Abandon,
|
|
193
|
-
..Default::default()
|
|
194
|
-
});
|
|
195
259
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
.expect("Child chould start OK");
|
|
201
|
-
barr.wait().await;
|
|
202
|
-
// Wait for cancel signal
|
|
203
|
-
ctx.cancelled().await;
|
|
204
|
-
// Cancel the child immediately
|
|
205
|
-
started.cancel(&ctx, "Die reason".to_string());
|
|
206
|
-
// Need to do something else, so we will see the child completing
|
|
207
|
-
ctx.timer(Duration::from_secs(1)).await;
|
|
208
|
-
started.result().await;
|
|
209
|
-
Ok(().into())
|
|
210
|
-
},
|
|
211
|
-
);
|
|
212
|
-
worker.register_wf(CHILD_WF_TYPE.to_string(), |_: WfContext| async move {
|
|
213
|
-
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(),
|
|
214
264
|
});
|
|
265
|
+
worker.register_workflow::<AbandonedChildResolvesPostCancelChild>();
|
|
215
266
|
|
|
267
|
+
let task_queue = starter.get_task_queue().to_owned();
|
|
216
268
|
worker
|
|
217
|
-
.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
WorkflowOptions::default(),
|
|
269
|
+
.submit_workflow(
|
|
270
|
+
AbandonedChildResolvesPostCancelParent::run,
|
|
271
|
+
(),
|
|
272
|
+
WorkflowStartOptions::new(task_queue, "parent-abandoner-resolving").build(),
|
|
222
273
|
)
|
|
223
274
|
.await
|
|
224
275
|
.unwrap();
|
|
225
276
|
let client = starter.get_client().await;
|
|
226
277
|
let canceller = async {
|
|
227
278
|
barr.wait().await;
|
|
228
|
-
client
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
None,
|
|
232
|
-
"die".to_string(),
|
|
233
|
-
None,
|
|
234
|
-
)
|
|
279
|
+
let handle = client.get_workflow_handle::<UntypedWorkflow>("parent-abandoner-resolving");
|
|
280
|
+
handle
|
|
281
|
+
.cancel(WorkflowCancelOptions::builder().reason("die").build())
|
|
235
282
|
.await
|
|
236
283
|
.unwrap();
|
|
237
284
|
};
|
|
@@ -241,14 +288,14 @@ async fn abandoned_child_resolves_post_cancel() {
|
|
|
241
288
|
tokio::join!(canceller, runner);
|
|
242
289
|
}
|
|
243
290
|
|
|
244
|
-
#[
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
let mut starter = CoreWfStarter::new(wf_name);
|
|
248
|
-
starter.worker_config.task_types = WorkerTaskTypes::workflow_only();
|
|
249
|
-
let mut worker = starter.worker().await;
|
|
291
|
+
#[workflow]
|
|
292
|
+
#[derive(Default)]
|
|
293
|
+
struct CancelledChildGetsReasonParent;
|
|
250
294
|
|
|
251
|
-
|
|
295
|
+
#[workflow_methods]
|
|
296
|
+
impl CancelledChildGetsReasonParent {
|
|
297
|
+
#[run]
|
|
298
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
252
299
|
let child = ctx.child_workflow(ChildWorkflowOptions {
|
|
253
300
|
workflow_id: format!("{}-child", ctx.task_queue()),
|
|
254
301
|
workflow_type: CHILD_WF_TYPE.to_owned(),
|
|
@@ -257,44 +304,63 @@ async fn cancelled_child_gets_reason() {
|
|
|
257
304
|
});
|
|
258
305
|
|
|
259
306
|
let started = child
|
|
260
|
-
.start(
|
|
307
|
+
.start()
|
|
261
308
|
.await
|
|
262
309
|
.into_started()
|
|
263
310
|
.expect("Child chould start OK");
|
|
264
|
-
|
|
265
|
-
started.cancel(&ctx, "Die reason".to_string());
|
|
311
|
+
started.cancel("Die reason".to_string());
|
|
266
312
|
let r = started.result().await;
|
|
267
313
|
let out = assert_matches!(r.status,
|
|
268
|
-
|
|
314
|
+
Some(child_workflow_result::Status::Completed(reason)) => reason);
|
|
269
315
|
assert_eq!(out.result.unwrap(), "Die reason".as_json_payload().unwrap());
|
|
270
|
-
Ok(()
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
let r = c.cancelled().await;
|
|
274
|
-
Ok(r.into())
|
|
275
|
-
});
|
|
316
|
+
Ok(())
|
|
317
|
+
}
|
|
318
|
+
}
|
|
276
319
|
|
|
277
|
-
|
|
278
|
-
|
|
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
|
+
}
|
|
279
331
|
}
|
|
280
332
|
|
|
281
|
-
#[rstest::rstest]
|
|
282
|
-
#[case::signal_then_result(true)]
|
|
283
|
-
#[case::signal_and_result_concurrent(false)]
|
|
284
333
|
#[tokio::test]
|
|
285
|
-
async fn
|
|
286
|
-
let
|
|
287
|
-
let
|
|
288
|
-
|
|
289
|
-
let
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
[ResponseType::AllHistory],
|
|
294
|
-
mock,
|
|
295
|
-
));
|
|
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>();
|
|
296
342
|
|
|
297
|
-
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<()> {
|
|
298
364
|
let child = ctx.child_workflow(ChildWorkflowOptions {
|
|
299
365
|
workflow_id: "child-id-1".to_string(),
|
|
300
366
|
workflow_type: "child".to_string(),
|
|
@@ -302,65 +368,91 @@ async fn signal_child_workflow(#[case] serial: bool) {
|
|
|
302
368
|
});
|
|
303
369
|
|
|
304
370
|
let start_res = child
|
|
305
|
-
.start(
|
|
371
|
+
.start()
|
|
306
372
|
.await
|
|
307
373
|
.into_started()
|
|
308
374
|
.expect("Child should get started");
|
|
375
|
+
let serial = ctx.state(|wf| wf.serial);
|
|
309
376
|
let (sigres, res) = if serial {
|
|
310
|
-
let sigres = start_res.signal(
|
|
377
|
+
let sigres = start_res.signal(Signal::new(SIGNAME, [b"Hi!"])).await;
|
|
311
378
|
let res = start_res.result().await;
|
|
312
379
|
(sigres, res)
|
|
313
380
|
} else {
|
|
314
|
-
let sigfut = start_res.signal(
|
|
381
|
+
let sigfut = start_res.signal(Signal::new(SIGNAME, [b"Hi!"]));
|
|
315
382
|
let resfut = start_res.result();
|
|
316
383
|
join!(sigfut, resfut)
|
|
317
384
|
};
|
|
318
385
|
sigres.expect("signal result is ok");
|
|
319
386
|
res.status.expect("child wf result is ok");
|
|
320
|
-
Ok(()
|
|
321
|
-
}
|
|
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
|
+
));
|
|
322
406
|
|
|
323
|
-
worker.
|
|
407
|
+
worker.register_workflow_with_factory(move || SignalChildWorkflowWf { serial });
|
|
408
|
+
let task_queue = worker.inner_mut().task_queue().to_owned();
|
|
324
409
|
worker
|
|
325
410
|
.submit_wf(
|
|
326
|
-
wf_id.to_owned(),
|
|
327
411
|
wf_type.to_owned(),
|
|
328
412
|
vec![],
|
|
329
|
-
|
|
413
|
+
WorkflowStartOptions::new(task_queue, wf_id.to_owned()).build(),
|
|
330
414
|
)
|
|
331
415
|
.await
|
|
332
416
|
.unwrap();
|
|
333
417
|
worker.run_until_done().await.unwrap();
|
|
334
418
|
}
|
|
335
419
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
workflow_type: "child".to_string(),
|
|
340
|
-
cancel_type: ChildWorkflowCancellationType::WaitCancellationCompleted,
|
|
341
|
-
..Default::default()
|
|
342
|
-
});
|
|
420
|
+
#[workflow]
|
|
421
|
+
#[derive(Default)]
|
|
422
|
+
struct ParentCancelsChildWf;
|
|
343
423
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
.
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
+
}
|
|
357
449
|
}
|
|
358
450
|
|
|
359
451
|
#[tokio::test]
|
|
360
452
|
async fn cancel_child_workflow() {
|
|
361
453
|
let t = canned_histories::single_child_workflow_cancelled("child-id-1");
|
|
362
454
|
let mut worker = build_fake_sdk(MockPollCfg::from_resps(t, [ResponseType::AllHistory]));
|
|
363
|
-
worker.
|
|
455
|
+
worker.register_workflow::<ParentCancelsChildWf>();
|
|
364
456
|
worker.run().await.unwrap();
|
|
365
457
|
}
|
|
366
458
|
|
|
@@ -480,6 +572,29 @@ async fn cancel_already_complete_child_ignored() {
|
|
|
480
572
|
.unwrap();
|
|
481
573
|
}
|
|
482
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
|
+
|
|
483
598
|
#[tokio::test]
|
|
484
599
|
async fn pass_child_workflow_summary_to_metadata() {
|
|
485
600
|
let wf_id = "1";
|
|
@@ -510,24 +625,16 @@ async fn pass_child_workflow_summary_to_metadata() {
|
|
|
510
625
|
});
|
|
511
626
|
|
|
512
627
|
let mut worker = mock_sdk_cfg(mock_cfg, |_| {});
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
workflow_type: "child".to_string(),
|
|
517
|
-
static_summary: Some("child summary".to_string()),
|
|
518
|
-
static_details: Some("child details".to_string()),
|
|
519
|
-
..Default::default()
|
|
520
|
-
})
|
|
521
|
-
.start(&ctx)
|
|
522
|
-
.await;
|
|
523
|
-
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(),
|
|
524
631
|
});
|
|
632
|
+
let task_queue = worker.inner_mut().task_queue().to_owned();
|
|
525
633
|
worker
|
|
526
634
|
.submit_wf(
|
|
527
|
-
wf_id.to_owned(),
|
|
528
635
|
wf_type.to_owned(),
|
|
529
636
|
vec![],
|
|
530
|
-
|
|
637
|
+
WorkflowStartOptions::new(task_queue, wf_id.to_owned()).build(),
|
|
531
638
|
)
|
|
532
639
|
.await
|
|
533
640
|
.unwrap();
|
|
@@ -555,38 +662,46 @@ impl Expectation {
|
|
|
555
662
|
#[fixture]
|
|
556
663
|
fn child_workflow_happy_hist() -> MockPollCfg {
|
|
557
664
|
let mut t = canned_histories::single_child_workflow("child-id-1");
|
|
558
|
-
t.set_wf_input(
|
|
665
|
+
t.set_wf_input((Expectation::Success as u8).as_json_payload().unwrap());
|
|
559
666
|
MockPollCfg::from_hist_builder(t)
|
|
560
667
|
}
|
|
561
668
|
|
|
562
669
|
#[fixture]
|
|
563
670
|
fn child_workflow_fail_hist() -> MockPollCfg {
|
|
564
671
|
let mut t = canned_histories::single_child_workflow_fail("child-id-1");
|
|
565
|
-
t.set_wf_input(
|
|
672
|
+
t.set_wf_input((Expectation::Failure as u8).as_json_payload().unwrap());
|
|
566
673
|
MockPollCfg::from_hist_builder(t)
|
|
567
674
|
}
|
|
568
675
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
workflow_id: "child-id-1".to_string(),
|
|
573
|
-
workflow_type: "child".to_string(),
|
|
574
|
-
..Default::default()
|
|
575
|
-
});
|
|
676
|
+
#[workflow]
|
|
677
|
+
#[derive(Default)]
|
|
678
|
+
struct ParentWf;
|
|
576
679
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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
|
+
}
|
|
590
705
|
}
|
|
591
706
|
}
|
|
592
707
|
|
|
@@ -619,7 +734,7 @@ async fn single_child_workflow_until_completion(mut mock_cfg: MockPollCfg) {
|
|
|
619
734
|
});
|
|
620
735
|
|
|
621
736
|
let mut worker = build_fake_sdk(mock_cfg);
|
|
622
|
-
worker.
|
|
737
|
+
worker.register_workflow::<ParentWf>();
|
|
623
738
|
worker.run().await.unwrap();
|
|
624
739
|
}
|
|
625
740
|
|
|
@@ -628,7 +743,7 @@ async fn single_child_workflow_start_fail() {
|
|
|
628
743
|
let child_wf_id = "child-id-1";
|
|
629
744
|
let mut t = TestHistoryBuilder::default();
|
|
630
745
|
t.add_by_type(EventType::WorkflowExecutionStarted);
|
|
631
|
-
t.set_wf_input(
|
|
746
|
+
t.set_wf_input((Expectation::StartFailure as u8).as_json_payload().unwrap());
|
|
632
747
|
t.add_full_wf_task();
|
|
633
748
|
let initiated_event_id = t.add(StartChildWorkflowExecutionInitiatedEventAttributes {
|
|
634
749
|
workflow_id: child_wf_id.to_owned(),
|
|
@@ -664,22 +779,30 @@ async fn single_child_workflow_start_fail() {
|
|
|
664
779
|
});
|
|
665
780
|
|
|
666
781
|
let mut worker = build_fake_sdk(mock_cfg);
|
|
667
|
-
worker.
|
|
782
|
+
worker.register_workflow::<ParentWf>();
|
|
668
783
|
worker.run().await.unwrap();
|
|
669
784
|
}
|
|
670
785
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
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
|
+
}
|
|
683
806
|
}
|
|
684
807
|
}
|
|
685
808
|
|
|
@@ -693,8 +816,6 @@ async fn single_child_workflow_cancel_before_sent() {
|
|
|
693
816
|
let mut mock_cfg = MockPollCfg::from_hist_builder(t);
|
|
694
817
|
mock_cfg.completion_asserts_from_expectations(|mut asserts| {
|
|
695
818
|
asserts.then(move |wft| {
|
|
696
|
-
// Workflow starts and cancels the child workflow, no commands should be sent besides
|
|
697
|
-
// workflow completion
|
|
698
819
|
assert_eq!(wft.commands.len(), 1);
|
|
699
820
|
assert_matches!(
|
|
700
821
|
wft.commands[0].command_type(),
|
|
@@ -704,6 +825,6 @@ async fn single_child_workflow_cancel_before_sent() {
|
|
|
704
825
|
});
|
|
705
826
|
|
|
706
827
|
let mut worker = build_fake_sdk(mock_cfg);
|
|
707
|
-
worker.
|
|
828
|
+
worker.register_workflow::<CancelBeforeSendWf>();
|
|
708
829
|
worker.run().await.unwrap();
|
|
709
830
|
}
|