@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,5 +1,7 @@
|
|
|
1
1
|
use crate::common::{CoreWfStarter, build_fake_sdk, init_core_and_create_wf};
|
|
2
|
-
use
|
|
2
|
+
use futures_util::{StreamExt, stream::FuturesUnordered};
|
|
3
|
+
use std::{future::Future, pin::Pin, time::Duration};
|
|
4
|
+
use temporalio_client::WorkflowStartOptions;
|
|
3
5
|
use temporalio_common::{
|
|
4
6
|
prost_dur,
|
|
5
7
|
protos::{
|
|
@@ -16,25 +18,41 @@ use temporalio_common::{
|
|
|
16
18
|
},
|
|
17
19
|
worker::WorkerTaskTypes,
|
|
18
20
|
};
|
|
19
|
-
use
|
|
21
|
+
use temporalio_macros::{workflow, workflow_methods};
|
|
22
|
+
use temporalio_sdk::{CancellableFuture, WorkflowContext, WorkflowResult};
|
|
20
23
|
use temporalio_sdk_core::test_help::{MockPollCfg, WorkerTestHelpers, drain_pollers_and_shutdown};
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
#[workflow]
|
|
26
|
+
#[derive(Default)]
|
|
27
|
+
pub(crate) struct TimerWf;
|
|
28
|
+
|
|
29
|
+
#[workflow_methods]
|
|
30
|
+
impl TimerWf {
|
|
31
|
+
#[run(name = "timer_wf_new")]
|
|
32
|
+
pub(crate) async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
33
|
+
ctx.timer(Duration::from_secs(1)).await;
|
|
34
|
+
Ok(())
|
|
35
|
+
}
|
|
25
36
|
}
|
|
26
37
|
|
|
27
38
|
#[tokio::test]
|
|
28
39
|
async fn timer_workflow_workflow_driver() {
|
|
29
40
|
let wf_name = "timer_wf_new";
|
|
30
41
|
let mut starter = CoreWfStarter::new(wf_name);
|
|
31
|
-
starter
|
|
32
|
-
.worker_config
|
|
33
|
-
.task_types(WorkerTaskTypes::workflow_only());
|
|
42
|
+
starter.sdk_config.task_types = WorkerTaskTypes::workflow_only();
|
|
34
43
|
let mut worker = starter.worker().await;
|
|
35
|
-
worker.
|
|
44
|
+
worker.register_workflow::<TimerWf>();
|
|
36
45
|
|
|
37
|
-
starter.
|
|
46
|
+
let task_queue = starter.get_task_queue().to_owned();
|
|
47
|
+
let workflow_id = starter.get_task_queue().to_owned();
|
|
48
|
+
worker
|
|
49
|
+
.submit_workflow(
|
|
50
|
+
TimerWf::run,
|
|
51
|
+
(),
|
|
52
|
+
WorkflowStartOptions::new(task_queue, workflow_id).build(),
|
|
53
|
+
)
|
|
54
|
+
.await
|
|
55
|
+
.unwrap();
|
|
38
56
|
worker.run_until_done().await.unwrap();
|
|
39
57
|
}
|
|
40
58
|
|
|
@@ -42,9 +60,7 @@ async fn timer_workflow_workflow_driver() {
|
|
|
42
60
|
async fn timer_workflow_manual() {
|
|
43
61
|
let mut starter = init_core_and_create_wf("timer_workflow").await;
|
|
44
62
|
let core = starter.get_worker().await;
|
|
45
|
-
starter
|
|
46
|
-
.worker_config
|
|
47
|
-
.task_types(WorkerTaskTypes::workflow_only());
|
|
63
|
+
starter.sdk_config.task_types = WorkerTaskTypes::workflow_only();
|
|
48
64
|
let task = core.poll_workflow_activation().await.unwrap();
|
|
49
65
|
core.complete_workflow_activation(WorkflowActivationCompletion::from_cmds(
|
|
50
66
|
task.run_id,
|
|
@@ -68,9 +84,7 @@ async fn timer_workflow_manual() {
|
|
|
68
84
|
async fn timer_cancel_workflow() {
|
|
69
85
|
let mut starter = init_core_and_create_wf("timer_cancel_workflow").await;
|
|
70
86
|
let core = starter.get_worker().await;
|
|
71
|
-
starter
|
|
72
|
-
.worker_config
|
|
73
|
-
.task_types(WorkerTaskTypes::workflow_only());
|
|
87
|
+
starter.sdk_config.task_types = WorkerTaskTypes::workflow_only();
|
|
74
88
|
let task = core.poll_workflow_activation().await.unwrap();
|
|
75
89
|
core.complete_workflow_activation(WorkflowActivationCompletion::from_cmds(
|
|
76
90
|
task.run_id,
|
|
@@ -118,30 +132,44 @@ async fn timer_immediate_cancel_workflow() {
|
|
|
118
132
|
.unwrap();
|
|
119
133
|
}
|
|
120
134
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
135
|
+
#[workflow]
|
|
136
|
+
#[derive(Default)]
|
|
137
|
+
struct ParallelTimerWf;
|
|
138
|
+
|
|
139
|
+
#[workflow_methods]
|
|
140
|
+
impl ParallelTimerWf {
|
|
141
|
+
#[run(name = "parallel_timers")]
|
|
142
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
143
|
+
let t1 = ctx.timer(Duration::from_secs(1));
|
|
144
|
+
let t2 = ctx.timer(Duration::from_secs(1));
|
|
145
|
+
let _ = temporalio_sdk::workflows::join!(t1, t2);
|
|
146
|
+
Ok(())
|
|
147
|
+
}
|
|
126
148
|
}
|
|
127
149
|
|
|
128
150
|
#[tokio::test]
|
|
129
151
|
async fn parallel_timers() {
|
|
130
152
|
let wf_name = "parallel_timers";
|
|
131
153
|
let mut starter = CoreWfStarter::new(wf_name);
|
|
132
|
-
starter
|
|
133
|
-
.worker_config
|
|
134
|
-
.task_types(WorkerTaskTypes::workflow_only());
|
|
154
|
+
starter.sdk_config.task_types = WorkerTaskTypes::workflow_only();
|
|
135
155
|
let mut worker = starter.worker().await;
|
|
136
|
-
worker.
|
|
156
|
+
worker.register_workflow::<ParallelTimerWf>();
|
|
137
157
|
|
|
138
158
|
starter.start_with_worker(wf_name, &mut worker).await;
|
|
139
159
|
worker.run_until_done().await.unwrap();
|
|
140
160
|
}
|
|
141
161
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
162
|
+
#[workflow]
|
|
163
|
+
#[derive(Default)]
|
|
164
|
+
struct HappyTimerWf;
|
|
165
|
+
|
|
166
|
+
#[workflow_methods]
|
|
167
|
+
impl HappyTimerWf {
|
|
168
|
+
#[run(name = DEFAULT_WORKFLOW_TYPE)]
|
|
169
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
170
|
+
ctx.timer(Duration::from_secs(5)).await;
|
|
171
|
+
Ok(())
|
|
172
|
+
}
|
|
145
173
|
}
|
|
146
174
|
|
|
147
175
|
#[tokio::test]
|
|
@@ -164,10 +192,23 @@ async fn test_fire_happy_path_inc() {
|
|
|
164
192
|
});
|
|
165
193
|
|
|
166
194
|
let mut worker = build_fake_sdk(mock_cfg);
|
|
167
|
-
worker.
|
|
195
|
+
worker.register_workflow::<HappyTimerWf>();
|
|
168
196
|
worker.run().await.unwrap();
|
|
169
197
|
}
|
|
170
198
|
|
|
199
|
+
#[workflow]
|
|
200
|
+
#[derive(Default)]
|
|
201
|
+
struct MismatchedTimerWf;
|
|
202
|
+
|
|
203
|
+
#[workflow_methods]
|
|
204
|
+
impl MismatchedTimerWf {
|
|
205
|
+
#[run(name = DEFAULT_WORKFLOW_TYPE)]
|
|
206
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
207
|
+
ctx.timer(Duration::from_secs(5)).await;
|
|
208
|
+
Ok(())
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
171
212
|
#[tokio::test]
|
|
172
213
|
async fn mismatched_timer_ids_errors() {
|
|
173
214
|
let t = canned_histories::single_timer("badid");
|
|
@@ -179,20 +220,24 @@ async fn mismatched_timer_ids_errors() {
|
|
|
179
220
|
if message.contains("Timer fired event did not have expected timer id 1"))
|
|
180
221
|
});
|
|
181
222
|
let mut worker = build_fake_sdk(mock_cfg);
|
|
182
|
-
worker.
|
|
183
|
-
ctx.timer(Duration::from_secs(5)).await;
|
|
184
|
-
Ok(().into())
|
|
185
|
-
});
|
|
223
|
+
worker.register_workflow::<MismatchedTimerWf>();
|
|
186
224
|
worker.run().await.unwrap();
|
|
187
225
|
}
|
|
188
226
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
227
|
+
#[workflow]
|
|
228
|
+
#[derive(Default)]
|
|
229
|
+
struct CancelTimerWf;
|
|
230
|
+
|
|
231
|
+
#[workflow_methods]
|
|
232
|
+
impl CancelTimerWf {
|
|
233
|
+
#[run(name = DEFAULT_WORKFLOW_TYPE)]
|
|
234
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
235
|
+
let cancel_timer_fut = ctx.timer(Duration::from_secs(500));
|
|
236
|
+
ctx.timer(Duration::from_secs(5)).await;
|
|
237
|
+
cancel_timer_fut.cancel();
|
|
238
|
+
cancel_timer_fut.await;
|
|
239
|
+
Ok(())
|
|
240
|
+
}
|
|
196
241
|
}
|
|
197
242
|
|
|
198
243
|
#[tokio::test]
|
|
@@ -217,10 +262,25 @@ async fn incremental_cancellation() {
|
|
|
217
262
|
});
|
|
218
263
|
|
|
219
264
|
let mut worker = build_fake_sdk(mock_cfg);
|
|
220
|
-
worker.
|
|
265
|
+
worker.register_workflow::<CancelTimerWf>();
|
|
221
266
|
worker.run().await.unwrap();
|
|
222
267
|
}
|
|
223
268
|
|
|
269
|
+
#[workflow]
|
|
270
|
+
#[derive(Default)]
|
|
271
|
+
struct CancelBeforeSentWf;
|
|
272
|
+
|
|
273
|
+
#[workflow_methods]
|
|
274
|
+
impl CancelBeforeSentWf {
|
|
275
|
+
#[run(name = DEFAULT_WORKFLOW_TYPE)]
|
|
276
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
277
|
+
let cancel_timer_fut = ctx.timer(Duration::from_secs(500));
|
|
278
|
+
cancel_timer_fut.cancel();
|
|
279
|
+
cancel_timer_fut.await;
|
|
280
|
+
Ok(())
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
224
284
|
#[tokio::test]
|
|
225
285
|
async fn cancel_before_sent_to_server() {
|
|
226
286
|
let mut t = TestHistoryBuilder::default();
|
|
@@ -238,12 +298,46 @@ async fn cancel_before_sent_to_server() {
|
|
|
238
298
|
});
|
|
239
299
|
});
|
|
240
300
|
let mut worker = build_fake_sdk(mock_cfg);
|
|
241
|
-
worker.
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
301
|
+
worker.register_workflow::<CancelBeforeSentWf>();
|
|
302
|
+
worker.run().await.unwrap();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
#[workflow]
|
|
306
|
+
#[derive(Default)]
|
|
307
|
+
struct WaitConditionWakerWf {
|
|
308
|
+
done: bool,
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
#[workflow_methods]
|
|
312
|
+
impl WaitConditionWakerWf {
|
|
313
|
+
#[run(name = DEFAULT_WORKFLOW_TYPE)]
|
|
314
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
315
|
+
let mut futs: FuturesUnordered<Pin<Box<dyn Future<Output = ()>>>> = FuturesUnordered::new();
|
|
316
|
+
|
|
317
|
+
// Future 1: await timer, then set flag via state_mut
|
|
318
|
+
let ctx1 = ctx.clone();
|
|
319
|
+
futs.push(Box::pin(async move {
|
|
320
|
+
ctx1.timer(Duration::from_millis(500)).await;
|
|
321
|
+
ctx1.state_mut(|s| s.done = true);
|
|
322
|
+
}));
|
|
323
|
+
|
|
324
|
+
// Future 2: wait_condition on the flag (waker-dependent inside FuturesUnordered)
|
|
325
|
+
let ctx2 = ctx.clone();
|
|
326
|
+
futs.push(Box::pin(async move {
|
|
327
|
+
ctx2.wait_condition(|s| s.done).await;
|
|
328
|
+
}));
|
|
329
|
+
|
|
330
|
+
// Drive both to completion
|
|
331
|
+
while futs.next().await.is_some() {}
|
|
332
|
+
Ok(())
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
#[tokio::test]
|
|
337
|
+
async fn wait_condition_waker_in_futures_unordered() {
|
|
338
|
+
let t = canned_histories::single_timer_wf_completes("1");
|
|
339
|
+
let mock_cfg = MockPollCfg::from_hist_builder(t);
|
|
340
|
+
let mut worker = build_fake_sdk(mock_cfg);
|
|
341
|
+
worker.register_workflow::<WaitConditionWakerWf>();
|
|
248
342
|
worker.run().await.unwrap();
|
|
249
343
|
}
|
|
@@ -2,8 +2,7 @@ use crate::common::{CoreWfStarter, SEARCH_ATTR_INT, SEARCH_ATTR_TXT, build_fake_
|
|
|
2
2
|
use assert_matches::assert_matches;
|
|
3
3
|
use std::{collections::HashMap, time::Duration};
|
|
4
4
|
use temporalio_client::{
|
|
5
|
-
|
|
6
|
-
WorkflowOptions,
|
|
5
|
+
UntypedWorkflow, WorkflowDescribeOptions, WorkflowGetResultOptions, WorkflowStartOptions,
|
|
7
6
|
};
|
|
8
7
|
use temporalio_common::{
|
|
9
8
|
protos::{
|
|
@@ -17,28 +16,36 @@ use temporalio_common::{
|
|
|
17
16
|
},
|
|
18
17
|
worker::WorkerTaskTypes,
|
|
19
18
|
};
|
|
20
|
-
use
|
|
19
|
+
use temporalio_macros::{workflow, workflow_methods};
|
|
20
|
+
use temporalio_sdk::{WorkflowContext, WorkflowResult, WorkflowTermination};
|
|
21
21
|
use temporalio_sdk_core::test_help::MockPollCfg;
|
|
22
22
|
use uuid::Uuid;
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
#[workflow]
|
|
25
|
+
#[derive(Default)]
|
|
26
|
+
struct SearchAttrUpdater;
|
|
27
|
+
|
|
28
|
+
#[workflow_methods]
|
|
29
|
+
impl SearchAttrUpdater {
|
|
30
|
+
#[run(name = "sends_upsert_search_attrs")]
|
|
31
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
32
|
+
let mut int_val = ctx
|
|
33
|
+
.search_attributes()
|
|
34
|
+
.indexed_fields
|
|
35
|
+
.get(SEARCH_ATTR_INT)
|
|
36
|
+
.cloned()
|
|
37
|
+
.unwrap_or_default();
|
|
38
|
+
let orig_val = int_val.data[0];
|
|
39
|
+
int_val.data[0] += 1;
|
|
40
|
+
ctx.upsert_search_attributes([
|
|
41
|
+
(SEARCH_ATTR_TXT.to_string(), "goodbye".as_json_payload()?),
|
|
42
|
+
(SEARCH_ATTR_INT.to_string(), int_val),
|
|
43
|
+
]);
|
|
44
|
+
if orig_val == 49 {
|
|
45
|
+
Err(WorkflowTermination::continue_as_new(Default::default()))
|
|
46
|
+
} else {
|
|
47
|
+
Ok(())
|
|
48
|
+
}
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
51
|
|
|
@@ -47,28 +54,25 @@ async fn sends_upsert() {
|
|
|
47
54
|
let wf_name = "sends_upsert_search_attrs";
|
|
48
55
|
let wf_id = Uuid::new_v4();
|
|
49
56
|
let mut starter = CoreWfStarter::new(wf_name);
|
|
50
|
-
starter
|
|
51
|
-
.worker_config
|
|
52
|
-
.task_types(WorkerTaskTypes::workflow_only());
|
|
57
|
+
starter.sdk_config.task_types = WorkerTaskTypes::workflow_only();
|
|
53
58
|
let mut worker = starter.worker().await;
|
|
54
59
|
|
|
55
|
-
worker.
|
|
60
|
+
worker.register_workflow::<SearchAttrUpdater>();
|
|
61
|
+
let task_queue = starter.get_task_queue().to_owned();
|
|
56
62
|
worker
|
|
57
63
|
.submit_wf(
|
|
58
|
-
wf_id.to_string(),
|
|
59
64
|
wf_name,
|
|
60
65
|
vec![],
|
|
61
|
-
|
|
62
|
-
search_attributes
|
|
66
|
+
WorkflowStartOptions::new(task_queue, wf_id.to_string())
|
|
67
|
+
.search_attributes(HashMap::from([
|
|
63
68
|
(
|
|
64
69
|
SEARCH_ATTR_TXT.to_string(),
|
|
65
70
|
"hello".as_json_payload().unwrap(),
|
|
66
71
|
),
|
|
67
72
|
(SEARCH_ATTR_INT.to_string(), 1.as_json_payload().unwrap()),
|
|
68
|
-
]))
|
|
69
|
-
execution_timeout
|
|
70
|
-
|
|
71
|
-
},
|
|
73
|
+
]))
|
|
74
|
+
.execution_timeout(Duration::from_secs(4))
|
|
75
|
+
.build(),
|
|
72
76
|
)
|
|
73
77
|
.await
|
|
74
78
|
.unwrap();
|
|
@@ -76,9 +80,11 @@ async fn sends_upsert() {
|
|
|
76
80
|
|
|
77
81
|
let client = starter.get_client().await;
|
|
78
82
|
let search_attrs = client
|
|
79
|
-
.
|
|
83
|
+
.get_workflow_handle::<UntypedWorkflow>(wf_id.to_string())
|
|
84
|
+
.describe(WorkflowDescribeOptions::default())
|
|
80
85
|
.await
|
|
81
86
|
.unwrap()
|
|
87
|
+
.raw_description
|
|
82
88
|
.workflow_execution_info
|
|
83
89
|
.unwrap()
|
|
84
90
|
.search_attributes
|
|
@@ -94,12 +100,41 @@ async fn sends_upsert() {
|
|
|
94
100
|
String::from_json_payload(txt_attr_payload).unwrap()
|
|
95
101
|
);
|
|
96
102
|
assert_eq!(3, usize::from_json_payload(int_attr_payload).unwrap());
|
|
97
|
-
let handle = client.
|
|
98
|
-
|
|
99
|
-
.
|
|
103
|
+
let handle = client.get_workflow_handle::<UntypedWorkflow>(wf_id.to_string());
|
|
104
|
+
handle
|
|
105
|
+
.get_result(WorkflowGetResultOptions::default())
|
|
100
106
|
.await
|
|
101
107
|
.unwrap();
|
|
102
|
-
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#[workflow]
|
|
111
|
+
#[derive(Default)]
|
|
112
|
+
struct UpsertTestWf;
|
|
113
|
+
|
|
114
|
+
#[workflow_methods]
|
|
115
|
+
impl UpsertTestWf {
|
|
116
|
+
#[run(name = DEFAULT_WORKFLOW_TYPE)]
|
|
117
|
+
async fn run(ctx: &mut WorkflowContext<Self>) -> WorkflowResult<()> {
|
|
118
|
+
const K1: &str = "foo";
|
|
119
|
+
const K2: &str = "bar";
|
|
120
|
+
ctx.upsert_search_attributes([
|
|
121
|
+
(
|
|
122
|
+
String::from(K1),
|
|
123
|
+
Payload {
|
|
124
|
+
data: vec![0x01],
|
|
125
|
+
..Default::default()
|
|
126
|
+
},
|
|
127
|
+
),
|
|
128
|
+
(
|
|
129
|
+
String::from(K2),
|
|
130
|
+
Payload {
|
|
131
|
+
data: vec![0x02],
|
|
132
|
+
..Default::default()
|
|
133
|
+
},
|
|
134
|
+
),
|
|
135
|
+
]);
|
|
136
|
+
Ok(())
|
|
137
|
+
}
|
|
103
138
|
}
|
|
104
139
|
|
|
105
140
|
#[tokio::test]
|
|
@@ -131,24 +166,6 @@ async fn upsert_search_attrs_from_workflow() {
|
|
|
131
166
|
});
|
|
132
167
|
|
|
133
168
|
let mut worker = build_fake_sdk(mock_cfg);
|
|
134
|
-
worker.
|
|
135
|
-
ctx.upsert_search_attributes([
|
|
136
|
-
(
|
|
137
|
-
String::from(k1),
|
|
138
|
-
Payload {
|
|
139
|
-
data: vec![0x01],
|
|
140
|
-
..Default::default()
|
|
141
|
-
},
|
|
142
|
-
),
|
|
143
|
-
(
|
|
144
|
-
String::from(k2),
|
|
145
|
-
Payload {
|
|
146
|
-
data: vec![0x02],
|
|
147
|
-
..Default::default()
|
|
148
|
-
},
|
|
149
|
-
),
|
|
150
|
-
]);
|
|
151
|
-
Ok(().into())
|
|
152
|
-
});
|
|
169
|
+
worker.register_workflow::<UpsertTestWf>();
|
|
153
170
|
worker.run().await.unwrap();
|
|
154
171
|
}
|