@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.
Files changed (209) hide show
  1. package/Cargo.lock +172 -70
  2. package/lib/native.d.ts +1 -1
  3. package/package.json +2 -2
  4. package/releases/aarch64-apple-darwin/index.node +0 -0
  5. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  6. package/releases/x86_64-apple-darwin/index.node +0 -0
  7. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  8. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  9. package/sdk-core/.github/workflows/per-pr.yml +6 -6
  10. package/sdk-core/AGENTS.md +41 -30
  11. package/sdk-core/Cargo.toml +3 -0
  12. package/sdk-core/README.md +15 -9
  13. package/sdk-core/crates/client/Cargo.toml +4 -0
  14. package/sdk-core/crates/client/README.md +139 -0
  15. package/sdk-core/crates/client/src/async_activity_handle.rs +297 -0
  16. package/sdk-core/crates/client/src/callback_based.rs +7 -0
  17. package/sdk-core/crates/client/src/errors.rs +294 -0
  18. package/sdk-core/crates/client/src/{raw.rs → grpc.rs} +280 -159
  19. package/sdk-core/crates/client/src/lib.rs +920 -1326
  20. package/sdk-core/crates/client/src/metrics.rs +24 -33
  21. package/sdk-core/crates/client/src/options_structs.rs +457 -0
  22. package/sdk-core/crates/client/src/replaceable.rs +5 -4
  23. package/sdk-core/crates/client/src/request_extensions.rs +8 -9
  24. package/sdk-core/crates/client/src/retry.rs +99 -54
  25. package/sdk-core/crates/client/src/{worker/mod.rs → worker.rs} +1 -1
  26. package/sdk-core/crates/client/src/workflow_handle.rs +826 -0
  27. package/sdk-core/crates/common/Cargo.toml +61 -2
  28. package/sdk-core/crates/common/build.rs +742 -12
  29. package/sdk-core/crates/common/protos/api_upstream/.github/workflows/ci.yml +2 -0
  30. package/sdk-core/crates/common/protos/api_upstream/Makefile +2 -1
  31. package/sdk-core/crates/common/protos/api_upstream/buf.yaml +0 -3
  32. package/sdk-core/crates/common/protos/api_upstream/cmd/check-path-conflicts/main.go +137 -0
  33. package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv2.json +1166 -770
  34. package/sdk-core/crates/common/protos/api_upstream/openapi/openapiv3.yaml +1243 -750
  35. package/sdk-core/crates/common/protos/api_upstream/temporal/api/deployment/v1/message.proto +2 -2
  36. package/sdk-core/crates/common/protos/api_upstream/temporal/api/enums/v1/workflow.proto +4 -3
  37. package/sdk-core/crates/common/protos/api_upstream/temporal/api/failure/v1/message.proto +1 -0
  38. package/sdk-core/crates/common/protos/api_upstream/temporal/api/history/v1/message.proto +4 -0
  39. package/sdk-core/crates/common/protos/api_upstream/temporal/api/namespace/v1/message.proto +6 -0
  40. package/sdk-core/crates/common/protos/api_upstream/temporal/api/nexus/v1/message.proto +16 -1
  41. package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +64 -6
  42. package/sdk-core/crates/common/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +88 -33
  43. package/sdk-core/crates/common/protos/local/temporal/sdk/core/nexus/nexus.proto +4 -2
  44. package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +4 -0
  45. package/sdk-core/crates/common/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +5 -5
  46. package/sdk-core/crates/common/src/activity_definition.rs +20 -0
  47. package/sdk-core/crates/common/src/data_converters.rs +770 -0
  48. package/sdk-core/crates/common/src/envconfig.rs +5 -0
  49. package/sdk-core/crates/common/src/lib.rs +15 -211
  50. package/sdk-core/crates/common/src/payload_visitor.rs +648 -0
  51. package/sdk-core/crates/common/src/priority.rs +110 -0
  52. package/sdk-core/crates/common/src/protos/canned_histories.rs +3 -0
  53. package/sdk-core/crates/common/src/protos/history_builder.rs +45 -0
  54. package/sdk-core/crates/common/src/protos/history_info.rs +2 -0
  55. package/sdk-core/crates/common/src/protos/mod.rs +122 -27
  56. package/sdk-core/crates/common/src/protos/task_token.rs +3 -3
  57. package/sdk-core/crates/common/src/protos/utilities.rs +11 -0
  58. package/sdk-core/crates/{sdk-core → common}/src/telemetry/log_export.rs +5 -7
  59. package/sdk-core/crates/common/src/telemetry/metrics/core.rs +125 -0
  60. package/sdk-core/crates/common/src/telemetry/metrics.rs +268 -223
  61. package/sdk-core/crates/{sdk-core → common}/src/telemetry/otel.rs +8 -13
  62. package/sdk-core/crates/{sdk-core → common}/src/telemetry/prometheus_meter.rs +49 -50
  63. package/sdk-core/crates/{sdk-core → common}/src/telemetry/prometheus_server.rs +2 -3
  64. package/sdk-core/crates/common/src/telemetry.rs +264 -4
  65. package/sdk-core/crates/common/src/worker.rs +68 -603
  66. package/sdk-core/crates/common/src/workflow_definition.rs +60 -0
  67. package/sdk-core/crates/macros/Cargo.toml +5 -1
  68. package/sdk-core/crates/macros/src/activities_definitions.rs +585 -0
  69. package/sdk-core/crates/macros/src/fsm_impl.rs +507 -0
  70. package/sdk-core/crates/macros/src/lib.rs +138 -512
  71. package/sdk-core/crates/macros/src/macro_utils.rs +106 -0
  72. package/sdk-core/crates/macros/src/workflow_definitions.rs +1224 -0
  73. package/sdk-core/crates/sdk/Cargo.toml +19 -6
  74. package/sdk-core/crates/sdk/README.md +415 -0
  75. package/sdk-core/crates/sdk/src/activities.rs +417 -0
  76. package/sdk-core/crates/sdk/src/interceptors.rs +1 -1
  77. package/sdk-core/crates/sdk/src/lib.rs +757 -442
  78. package/sdk-core/crates/sdk/src/workflow_context/options.rs +45 -35
  79. package/sdk-core/crates/sdk/src/workflow_context.rs +1033 -289
  80. package/sdk-core/crates/sdk/src/workflow_future.rs +277 -213
  81. package/sdk-core/crates/sdk/src/workflows.rs +711 -0
  82. package/sdk-core/crates/sdk-core/Cargo.toml +57 -64
  83. package/sdk-core/crates/sdk-core/benches/workflow_replay_bench.rs +41 -35
  84. package/sdk-core/crates/sdk-core/machine_coverage/ActivityMachine_Coverage.puml +1 -1
  85. package/sdk-core/crates/sdk-core/src/abstractions.rs +6 -10
  86. package/sdk-core/crates/sdk-core/src/core_tests/activity_tasks.rs +6 -5
  87. package/sdk-core/crates/sdk-core/src/core_tests/mod.rs +13 -15
  88. package/sdk-core/crates/sdk-core/src/core_tests/queries.rs +21 -25
  89. package/sdk-core/crates/sdk-core/src/core_tests/replay_flag.rs +7 -10
  90. package/sdk-core/crates/sdk-core/src/core_tests/updates.rs +14 -17
  91. package/sdk-core/crates/sdk-core/src/core_tests/workers.rs +493 -26
  92. package/sdk-core/crates/sdk-core/src/core_tests/workflow_tasks.rs +4 -8
  93. package/sdk-core/crates/sdk-core/src/ephemeral_server/mod.rs +7 -7
  94. package/sdk-core/crates/sdk-core/src/histfetch.rs +20 -10
  95. package/sdk-core/crates/sdk-core/src/lib.rs +41 -111
  96. package/sdk-core/crates/sdk-core/src/pollers/mod.rs +4 -9
  97. package/sdk-core/crates/sdk-core/src/pollers/poll_buffer.rs +118 -19
  98. package/sdk-core/crates/sdk-core/src/protosext/mod.rs +2 -2
  99. package/sdk-core/crates/sdk-core/src/replay/mod.rs +14 -5
  100. package/sdk-core/crates/sdk-core/src/telemetry/metrics.rs +179 -196
  101. package/sdk-core/crates/sdk-core/src/telemetry/mod.rs +3 -280
  102. package/sdk-core/crates/sdk-core/src/test_help/integ_helpers.rs +6 -9
  103. package/sdk-core/crates/sdk-core/src/test_help/unit_helpers.rs +3 -6
  104. package/sdk-core/crates/sdk-core/src/worker/activities/local_activities.rs +11 -14
  105. package/sdk-core/crates/sdk-core/src/worker/activities.rs +16 -19
  106. package/sdk-core/crates/sdk-core/src/worker/client/mocks.rs +9 -5
  107. package/sdk-core/crates/sdk-core/src/worker/client.rs +103 -81
  108. package/sdk-core/crates/sdk-core/src/worker/heartbeat.rs +7 -11
  109. package/sdk-core/crates/sdk-core/src/worker/mod.rs +1124 -229
  110. package/sdk-core/crates/sdk-core/src/worker/nexus.rs +145 -23
  111. package/sdk-core/crates/sdk-core/src/worker/slot_provider.rs +2 -2
  112. package/sdk-core/crates/sdk-core/src/worker/tuner/fixed_size.rs +2 -2
  113. package/sdk-core/crates/sdk-core/src/worker/tuner/resource_based.rs +13 -13
  114. package/sdk-core/crates/sdk-core/src/worker/tuner.rs +28 -8
  115. package/sdk-core/crates/sdk-core/src/worker/workflow/driven_workflow.rs +9 -3
  116. package/sdk-core/crates/sdk-core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +21 -22
  117. package/sdk-core/crates/sdk-core/src/worker/workflow/machines/workflow_machines.rs +19 -4
  118. package/sdk-core/crates/sdk-core/src/worker/workflow/managed_run.rs +14 -18
  119. package/sdk-core/crates/sdk-core/src/worker/workflow/mod.rs +4 -6
  120. package/sdk-core/crates/sdk-core/src/worker/workflow/run_cache.rs +4 -7
  121. package/sdk-core/crates/sdk-core/src/worker/workflow/wft_extraction.rs +2 -4
  122. package/sdk-core/crates/sdk-core/src/worker/workflow/wft_poller.rs +8 -9
  123. package/sdk-core/crates/sdk-core/src/worker/workflow/workflow_stream.rs +1 -3
  124. package/sdk-core/crates/sdk-core/tests/activities_procmacro.rs +6 -0
  125. package/sdk-core/crates/sdk-core/tests/activities_trybuild/basic_pass.rs +54 -0
  126. package/sdk-core/crates/sdk-core/tests/activities_trybuild/invalid_self_type_fail.rs +18 -0
  127. package/sdk-core/crates/sdk-core/tests/activities_trybuild/invalid_self_type_fail.stderr +5 -0
  128. package/sdk-core/crates/sdk-core/tests/activities_trybuild/missing_context_fail.rs +14 -0
  129. package/sdk-core/crates/sdk-core/tests/activities_trybuild/missing_context_fail.stderr +5 -0
  130. package/sdk-core/crates/sdk-core/tests/activities_trybuild/multi_arg_pass.rs +48 -0
  131. package/sdk-core/crates/sdk-core/tests/activities_trybuild/no_input_pass.rs +14 -0
  132. package/sdk-core/crates/sdk-core/tests/activities_trybuild/no_return_type_pass.rs +19 -0
  133. package/sdk-core/crates/sdk-core/tests/cloud_tests.rs +14 -5
  134. package/sdk-core/crates/sdk-core/tests/common/activity_functions.rs +55 -0
  135. package/sdk-core/crates/sdk-core/tests/common/mod.rs +241 -196
  136. package/sdk-core/crates/sdk-core/tests/common/workflows.rs +41 -28
  137. package/sdk-core/crates/sdk-core/tests/global_metric_tests.rs +3 -5
  138. package/sdk-core/crates/sdk-core/tests/heavy_tests/fuzzy_workflow.rs +73 -64
  139. package/sdk-core/crates/sdk-core/tests/heavy_tests.rs +298 -252
  140. package/sdk-core/crates/sdk-core/tests/integ_tests/async_activity_client_tests.rs +230 -0
  141. package/sdk-core/crates/sdk-core/tests/integ_tests/client_tests.rs +94 -57
  142. package/sdk-core/crates/sdk-core/tests/integ_tests/data_converter_tests.rs +381 -0
  143. package/sdk-core/crates/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +16 -12
  144. package/sdk-core/crates/sdk-core/tests/integ_tests/heartbeat_tests.rs +48 -40
  145. package/sdk-core/crates/sdk-core/tests/integ_tests/metrics_tests.rs +327 -255
  146. package/sdk-core/crates/sdk-core/tests/integ_tests/pagination_tests.rs +50 -45
  147. package/sdk-core/crates/sdk-core/tests/integ_tests/polling_tests.rs +147 -126
  148. package/sdk-core/crates/sdk-core/tests/integ_tests/queries_tests.rs +103 -89
  149. package/sdk-core/crates/sdk-core/tests/integ_tests/update_tests.rs +609 -453
  150. package/sdk-core/crates/sdk-core/tests/integ_tests/visibility_tests.rs +80 -62
  151. package/sdk-core/crates/sdk-core/tests/integ_tests/worker_heartbeat_tests.rs +360 -231
  152. package/sdk-core/crates/sdk-core/tests/integ_tests/worker_tests.rs +248 -185
  153. package/sdk-core/crates/sdk-core/tests/integ_tests/worker_versioning_tests.rs +52 -43
  154. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_client_tests.rs +180 -0
  155. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/activities.rs +428 -315
  156. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +82 -56
  157. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +56 -28
  158. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +364 -243
  159. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/client_interactions.rs +552 -0
  160. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +101 -42
  161. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +243 -147
  162. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/eager.rs +98 -28
  163. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +1475 -1036
  164. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +73 -41
  165. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +397 -238
  166. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/patches.rs +414 -189
  167. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/queries.rs +415 -0
  168. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/replay.rs +96 -36
  169. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/resets.rs +154 -137
  170. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/signals.rs +183 -105
  171. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +85 -38
  172. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/timers.rs +142 -40
  173. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +73 -54
  174. package/sdk-core/crates/sdk-core/tests/integ_tests/workflow_tests.rs +363 -226
  175. package/sdk-core/crates/sdk-core/tests/main.rs +17 -15
  176. package/sdk-core/crates/sdk-core/tests/manual_tests.rs +207 -152
  177. package/sdk-core/crates/sdk-core/tests/shared_tests/mod.rs +65 -34
  178. package/sdk-core/crates/sdk-core/tests/shared_tests/priority.rs +107 -84
  179. package/sdk-core/crates/sdk-core/tests/workflows_procmacro.rs +6 -0
  180. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/async_query_fail.rs +26 -0
  181. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/async_query_fail.stderr +5 -0
  182. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/basic_pass.rs +49 -0
  183. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/minimal_pass.rs +21 -0
  184. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/mut_query_fail.rs +26 -0
  185. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/mut_query_fail.stderr +5 -0
  186. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/sync_run_fail.rs +21 -0
  187. package/sdk-core/crates/sdk-core/tests/workflows_trybuild/sync_run_fail.stderr +5 -0
  188. package/sdk-core/crates/sdk-core-c-bridge/Cargo.toml +7 -1
  189. package/sdk-core/crates/sdk-core-c-bridge/include/temporal-sdk-core-c-bridge.h +14 -14
  190. package/sdk-core/crates/sdk-core-c-bridge/src/client.rs +83 -74
  191. package/sdk-core/crates/sdk-core-c-bridge/src/metric.rs +9 -14
  192. package/sdk-core/crates/sdk-core-c-bridge/src/runtime.rs +1 -2
  193. package/sdk-core/crates/sdk-core-c-bridge/src/tests/context.rs +13 -13
  194. package/sdk-core/crates/sdk-core-c-bridge/src/tests/mod.rs +6 -6
  195. package/sdk-core/crates/sdk-core-c-bridge/src/tests/utils.rs +3 -4
  196. package/sdk-core/crates/sdk-core-c-bridge/src/worker.rs +62 -75
  197. package/sdk-core/rustfmt.toml +2 -1
  198. package/src/client.rs +205 -318
  199. package/src/metrics.rs +22 -30
  200. package/src/runtime.rs +4 -5
  201. package/src/worker.rs +16 -19
  202. package/ts/native.ts +1 -1
  203. package/sdk-core/crates/client/src/workflow_handle/mod.rs +0 -212
  204. package/sdk-core/crates/common/src/errors.rs +0 -85
  205. package/sdk-core/crates/common/tests/worker_task_types_test.rs +0 -129
  206. package/sdk-core/crates/sdk/src/activity_context.rs +0 -238
  207. package/sdk-core/crates/sdk/src/app_data.rs +0 -37
  208. package/sdk-core/crates/sdk-core/tests/integ_tests/activity_functions.rs +0 -5
  209. 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::{WorkflowClientTrait, WorkflowOptions};
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, WfContext, WfExitValue, WorkflowResult,
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
- async fn child_wf(ctx: WfContext) -> WorkflowResult<()> {
53
- assert_eq!(
54
- ctx.workflow_initial_info()
55
- .parent_workflow_info
56
- .as_ref()
57
- .unwrap()
58
- .workflow_id,
59
- ctx.workflow_initial_info()
60
- .root_workflow
61
- .as_ref()
62
- .unwrap()
63
- .workflow_id
64
- );
65
- Ok(().into())
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
- async fn happy_parent(ctx: WfContext) -> WorkflowResult<()> {
69
- let child = ctx.child_workflow(ChildWorkflowOptions {
70
- workflow_id: "child-1".to_owned(),
71
- workflow_type: CHILD_WF_TYPE.to_owned(),
72
- ..Default::default()
73
- });
76
+ #[workflow]
77
+ #[derive(Default)]
78
+ struct HappyParent;
74
79
 
75
- let started = child
76
- .start(&ctx)
77
- .await
78
- .into_started()
79
- .expect("Child chould start OK");
80
- match started.result().await.status {
81
- Some(child_workflow_result::Status::Completed(Success { .. })) => Ok(().into()),
82
- _ => Err(anyhow!("Unexpected child WF status")),
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.worker_config.task_types = WorkerTaskTypes::workflow_only();
105
+ starter.sdk_config.task_types = WorkerTaskTypes::workflow_only();
90
106
  let mut worker = starter.worker().await;
91
107
 
92
- worker.register_wf(PARENT_WF_TYPE.to_string(), happy_parent);
93
- worker.register_wf(CHILD_WF_TYPE.to_string(), child_wf);
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
- WorkflowOptions::default(),
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.worker_config.task_types = WorkerTaskTypes::workflow_only();
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
- let started = child
126
- .start(&ctx)
127
- .await
128
- .into_started()
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
- .submit_wf(
148
- "parent-abandoner".to_string(),
149
- PARENT_WF_TYPE.to_owned(),
150
- vec![],
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
- .cancel_workflow_execution(
160
- "parent-abandoner".to_string(),
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
- .cancel_workflow_execution("abandoned-child".to_string(), None, "die".to_string(), None)
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.worker_config.task_types = WorkerTaskTypes::workflow_only();
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
- let started = child
197
- .start(&ctx)
198
- .await
199
- .into_started()
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
- .submit_wf(
218
- "parent-abandoner-resolving".to_string(),
219
- PARENT_WF_TYPE.to_owned(),
220
- vec![],
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
- .cancel_workflow_execution(
230
- "parent-abandoner-resolving".to_string(),
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
- #[tokio::test]
245
- async fn cancelled_child_gets_reason() {
246
- let wf_name = "cancelled-child-gets-reason";
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
- worker.register_wf(wf_name.to_string(), move |ctx: WfContext| async move {
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(&ctx)
307
+ .start()
261
308
  .await
262
309
  .into_started()
263
310
  .expect("Child chould start OK");
264
- // Cancel the child after start
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
- Some(child_workflow_result::Status::Completed(reason)) => reason);
314
+ Some(child_workflow_result::Status::Completed(reason)) => reason);
269
315
  assert_eq!(out.result.unwrap(), "Die reason".as_json_payload().unwrap());
270
- Ok(().into())
271
- });
272
- worker.register_wf(CHILD_WF_TYPE.to_string(), |c: WfContext| async move {
273
- let r = c.cancelled().await;
274
- Ok(r.into())
275
- });
316
+ Ok(())
317
+ }
318
+ }
276
319
 
277
- starter.start_with_worker(wf_name, &mut worker).await;
278
- worker.run_until_done().await.unwrap();
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 signal_child_workflow(#[case] serial: bool) {
286
- let wf_id = "fakeid";
287
- let wf_type = DEFAULT_WORKFLOW_TYPE;
288
- let t = canned_histories::single_child_workflow_signaled("child-id-1", SIGNAME);
289
- let mock = mock_worker_client();
290
- let mut worker = mock_sdk(MockPollCfg::from_resp_batches(
291
- wf_id,
292
- t,
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 wf = move |ctx: WfContext| async move {
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(&ctx)
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(&ctx, Signal::new(SIGNAME, [b"Hi!"])).await;
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(&ctx, Signal::new(SIGNAME, [b"Hi!"]));
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(().into())
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.register_wf(wf_type.to_owned(), wf);
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
- WorkflowOptions::default(),
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
- async fn parent_cancels_child_wf(ctx: WfContext) -> WorkflowResult<()> {
337
- let child = ctx.child_workflow(ChildWorkflowOptions {
338
- workflow_id: "child-id-1".to_string(),
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
- let start_res = child
345
- .start(&ctx)
346
- .await
347
- .into_started()
348
- .expect("Child should get started");
349
- start_res.cancel(&ctx, "cancel reason".to_string());
350
- let stat = start_res
351
- .result()
352
- .await
353
- .status
354
- .expect("child wf result is ok");
355
- assert_matches!(stat, child_workflow_result::Status::Cancelled(_));
356
- Ok(().into())
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.register_wf(DEFAULT_WORKFLOW_TYPE, parent_cancels_child_wf);
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
- worker.register_wf(wf_type, move |ctx: WfContext| async move {
514
- ctx.child_workflow(ChildWorkflowOptions {
515
- workflow_id: wf_id.to_string(),
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
- WorkflowOptions::default(),
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(Payload::from([Expectation::Success as u8]));
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(Payload::from([Expectation::Failure as u8]));
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
- async fn parent_wf(ctx: WfContext) -> WorkflowResult<()> {
570
- let expectation = Expectation::try_from_u8(ctx.get_args()[0].data[0]).unwrap();
571
- let child = ctx.child_workflow(ChildWorkflowOptions {
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
- let start_res = child.start(&ctx).await;
578
- match (expectation, &start_res.status) {
579
- (Expectation::Success | Expectation::Failure, StartStatus::Succeeded(_)) => {}
580
- (Expectation::StartFailure, StartStatus::Failed(_)) => return Ok(().into()),
581
- _ => return Err(anyhow!("Unexpected start status")),
582
- };
583
- match (
584
- expectation,
585
- start_res.into_started().unwrap().result().await.status,
586
- ) {
587
- (Expectation::Success, Some(child_workflow_result::Status::Completed(_))) => Ok(().into()),
588
- (Expectation::Failure, _) => Ok(().into()),
589
- _ => Err(anyhow!("Unexpected child WF status")),
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.register_wf(DEFAULT_WORKFLOW_TYPE, parent_wf);
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(Payload::from([Expectation::StartFailure as u8]));
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.register_wf(DEFAULT_WORKFLOW_TYPE, parent_wf);
782
+ worker.register_workflow::<ParentWf>();
668
783
  worker.run().await.unwrap();
669
784
  }
670
785
 
671
- async fn cancel_before_send_wf(ctx: WfContext) -> WorkflowResult<()> {
672
- let workflow_id = "child-id-1";
673
- let child = ctx.child_workflow(ChildWorkflowOptions {
674
- workflow_id: workflow_id.to_string(),
675
- workflow_type: "child".to_string(),
676
- ..Default::default()
677
- });
678
- let start = child.start(&ctx);
679
- start.cancel(&ctx);
680
- match start.await.status {
681
- StartStatus::Cancelled(_) => Ok(().into()),
682
- _ => Err(anyhow!("Unexpected start status")),
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.register_wf(DEFAULT_WORKFLOW_TYPE, cancel_before_send_wf);
828
+ worker.register_workflow::<CancelBeforeSendWf>();
708
829
  worker.run().await.unwrap();
709
830
  }