@temporalio/core-bridge 1.13.0 → 1.13.2
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 +239 -382
- package/Cargo.toml +11 -11
- package/lib/native.d.ts +10 -3
- package/package.json +3 -3
- 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/.cargo/config.toml +71 -11
- package/sdk-core/.clippy.toml +1 -0
- package/sdk-core/.github/workflows/heavy.yml +2 -0
- package/sdk-core/.github/workflows/per-pr.yml +50 -18
- package/sdk-core/ARCHITECTURE.md +44 -48
- package/sdk-core/Cargo.toml +26 -7
- package/sdk-core/README.md +4 -0
- package/sdk-core/arch_docs/diagrams/TimerMachine_Coverage.puml +14 -0
- package/sdk-core/arch_docs/diagrams/initial_event_history.png +0 -0
- package/sdk-core/arch_docs/sdks_intro.md +299 -0
- package/sdk-core/client/Cargo.toml +8 -7
- package/sdk-core/client/src/callback_based.rs +1 -2
- package/sdk-core/client/src/lib.rs +485 -299
- package/sdk-core/client/src/metrics.rs +32 -8
- package/sdk-core/client/src/proxy.rs +124 -5
- package/sdk-core/client/src/raw.rs +598 -307
- package/sdk-core/client/src/replaceable.rs +253 -0
- package/sdk-core/client/src/retry.rs +9 -6
- package/sdk-core/client/src/worker_registry/mod.rs +19 -3
- package/sdk-core/client/src/workflow_handle/mod.rs +20 -17
- package/sdk-core/core/Cargo.toml +100 -31
- package/sdk-core/core/src/core_tests/activity_tasks.rs +55 -225
- package/sdk-core/core/src/core_tests/mod.rs +2 -8
- package/sdk-core/core/src/core_tests/queries.rs +3 -5
- package/sdk-core/core/src/core_tests/replay_flag.rs +3 -62
- package/sdk-core/core/src/core_tests/updates.rs +4 -5
- package/sdk-core/core/src/core_tests/workers.rs +4 -3
- package/sdk-core/core/src/core_tests/workflow_cancels.rs +10 -7
- package/sdk-core/core/src/core_tests/workflow_tasks.rs +28 -291
- package/sdk-core/core/src/ephemeral_server/mod.rs +15 -3
- package/sdk-core/core/src/internal_flags.rs +11 -1
- package/sdk-core/core/src/lib.rs +50 -36
- package/sdk-core/core/src/pollers/mod.rs +5 -5
- package/sdk-core/core/src/pollers/poll_buffer.rs +2 -2
- package/sdk-core/core/src/protosext/mod.rs +13 -5
- package/sdk-core/core/src/protosext/protocol_messages.rs +4 -11
- package/sdk-core/core/src/retry_logic.rs +256 -108
- package/sdk-core/core/src/telemetry/metrics.rs +1 -0
- package/sdk-core/core/src/telemetry/mod.rs +8 -2
- package/sdk-core/core/src/telemetry/prometheus_meter.rs +2 -2
- package/sdk-core/core/src/test_help/integ_helpers.rs +971 -0
- package/sdk-core/core/src/test_help/mod.rs +10 -1100
- package/sdk-core/core/src/test_help/unit_helpers.rs +218 -0
- package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +42 -6
- package/sdk-core/core/src/worker/activities/local_activities.rs +19 -19
- package/sdk-core/core/src/worker/activities.rs +10 -3
- package/sdk-core/core/src/worker/client/mocks.rs +3 -3
- package/sdk-core/core/src/worker/client.rs +130 -93
- package/sdk-core/core/src/worker/heartbeat.rs +12 -13
- package/sdk-core/core/src/worker/mod.rs +31 -21
- package/sdk-core/core/src/worker/nexus.rs +14 -3
- package/sdk-core/core/src/worker/slot_provider.rs +9 -0
- package/sdk-core/core/src/worker/tuner.rs +159 -0
- package/sdk-core/core/src/worker/workflow/history_update.rs +3 -265
- package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +1 -54
- package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +0 -82
- package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +0 -67
- package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +1 -192
- package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +0 -43
- package/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +6 -554
- package/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +0 -71
- package/sdk-core/core/src/worker/workflow/machines/nexus_operation_state_machine.rs +102 -3
- package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +10 -539
- package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +0 -139
- package/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +1 -119
- package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +6 -63
- package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +9 -4
- package/sdk-core/core/src/worker/workflow/mod.rs +5 -1
- package/sdk-core/core/src/worker/workflow/workflow_stream.rs +8 -3
- package/sdk-core/core-api/Cargo.toml +4 -4
- package/sdk-core/core-api/src/envconfig.rs +153 -54
- package/sdk-core/core-api/src/lib.rs +68 -0
- package/sdk-core/core-api/src/telemetry/metrics.rs +2 -1
- package/sdk-core/core-api/src/telemetry.rs +13 -0
- package/sdk-core/core-c-bridge/Cargo.toml +13 -8
- package/sdk-core/core-c-bridge/include/temporal-sdk-core-c-bridge.h +184 -22
- package/sdk-core/core-c-bridge/src/client.rs +462 -184
- package/sdk-core/core-c-bridge/src/envconfig.rs +314 -0
- package/sdk-core/core-c-bridge/src/lib.rs +1 -0
- package/sdk-core/core-c-bridge/src/random.rs +4 -4
- package/sdk-core/core-c-bridge/src/runtime.rs +22 -23
- package/sdk-core/core-c-bridge/src/testing.rs +1 -4
- package/sdk-core/core-c-bridge/src/tests/context.rs +31 -31
- package/sdk-core/core-c-bridge/src/tests/mod.rs +32 -28
- package/sdk-core/core-c-bridge/src/tests/utils.rs +7 -7
- package/sdk-core/core-c-bridge/src/worker.rs +319 -66
- package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +6 -1
- package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/dupe_transitions_fail.stderr +5 -5
- package/sdk-core/sdk/Cargo.toml +8 -2
- package/sdk-core/sdk/src/activity_context.rs +1 -1
- package/sdk-core/sdk/src/app_data.rs +1 -1
- package/sdk-core/sdk/src/interceptors.rs +1 -4
- package/sdk-core/sdk/src/lib.rs +1 -5
- package/sdk-core/sdk/src/workflow_context/options.rs +10 -1
- package/sdk-core/sdk/src/workflow_future.rs +1 -1
- package/sdk-core/sdk-core-protos/Cargo.toml +6 -6
- package/sdk-core/sdk-core-protos/build.rs +10 -23
- package/sdk-core/sdk-core-protos/protos/api_upstream/.github/workflows/create-release.yml +9 -1
- package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv2.json +254 -5
- package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv3.yaml +234 -5
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/common/v1/message.proto +1 -1
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/deployment/v1/message.proto +6 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/namespace/v1/message.proto +6 -2
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +60 -2
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +30 -6
- package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +2 -0
- package/sdk-core/{test-utils → sdk-core-protos}/src/canned_histories.rs +5 -5
- package/sdk-core/sdk-core-protos/src/history_builder.rs +2 -2
- package/sdk-core/sdk-core-protos/src/lib.rs +25 -9
- package/sdk-core/sdk-core-protos/src/test_utils.rs +89 -0
- package/sdk-core/sdk-core-protos/src/utilities.rs +14 -5
- package/sdk-core/tests/c_bridge_smoke_test.c +10 -0
- package/sdk-core/tests/cloud_tests.rs +10 -8
- package/sdk-core/tests/common/http_proxy.rs +134 -0
- package/sdk-core/{test-utils/src/lib.rs → tests/common/mod.rs} +214 -281
- package/sdk-core/{test-utils/src → tests/common}/workflows.rs +4 -3
- package/sdk-core/tests/fuzzy_workflow.rs +1 -1
- package/sdk-core/tests/global_metric_tests.rs +8 -7
- package/sdk-core/tests/heavy_tests.rs +7 -3
- package/sdk-core/tests/integ_tests/client_tests.rs +111 -24
- package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +14 -9
- package/sdk-core/tests/integ_tests/heartbeat_tests.rs +4 -4
- package/sdk-core/tests/integ_tests/metrics_tests.rs +114 -14
- package/sdk-core/tests/integ_tests/pagination_tests.rs +273 -0
- package/sdk-core/tests/integ_tests/polling_tests.rs +311 -93
- package/sdk-core/tests/integ_tests/queries_tests.rs +4 -4
- package/sdk-core/tests/integ_tests/update_tests.rs +13 -7
- package/sdk-core/tests/integ_tests/visibility_tests.rs +26 -9
- package/sdk-core/tests/integ_tests/worker_tests.rs +668 -13
- package/sdk-core/tests/integ_tests/worker_versioning_tests.rs +40 -24
- package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +244 -11
- package/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +1 -1
- package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +78 -2
- package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +61 -2
- package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +465 -7
- package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +41 -2
- package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +315 -3
- package/sdk-core/tests/integ_tests/workflow_tests/eager.rs +1 -1
- package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +1990 -14
- package/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +65 -2
- package/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +123 -23
- package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +525 -3
- package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +65 -16
- package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +32 -23
- package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +126 -5
- package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +1 -2
- package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +124 -8
- package/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +62 -2
- package/sdk-core/tests/integ_tests/workflow_tests.rs +67 -8
- package/sdk-core/tests/main.rs +26 -17
- package/sdk-core/tests/manual_tests.rs +5 -1
- package/sdk-core/tests/runner.rs +22 -40
- package/sdk-core/tests/shared_tests/mod.rs +1 -1
- package/sdk-core/tests/shared_tests/priority.rs +1 -1
- package/sdk-core/{core/benches/workflow_replay.rs → tests/workflow_replay_bench.rs} +10 -5
- package/src/client.rs +97 -20
- package/src/helpers/callbacks.rs +4 -4
- package/src/helpers/errors.rs +7 -1
- package/src/helpers/handles.rs +1 -0
- package/src/helpers/try_from_js.rs +4 -3
- package/src/lib.rs +3 -2
- package/src/metrics.rs +3 -0
- package/src/runtime.rs +5 -2
- package/src/worker.rs +9 -12
- package/ts/native.ts +13 -3
- package/sdk-core/arch_docs/diagrams/workflow_internals.svg +0 -1
- package/sdk-core/core/src/core_tests/child_workflows.rs +0 -281
- package/sdk-core/core/src/core_tests/determinism.rs +0 -318
- package/sdk-core/core/src/core_tests/local_activities.rs +0 -1442
- package/sdk-core/test-utils/Cargo.toml +0 -38
- package/sdk-core/test-utils/src/histfetch.rs +0 -28
- package/sdk-core/test-utils/src/interceptors.rs +0 -46
|
@@ -58,6 +58,7 @@ pub(super) struct SlotProvider {
|
|
|
58
58
|
task_queue: String,
|
|
59
59
|
wft_semaphore: MeteredPermitDealer<WorkflowSlotKind>,
|
|
60
60
|
external_wft_tx: WFTStreamSender,
|
|
61
|
+
deployment_options: Option<temporal_sdk_core_api::worker::WorkerDeploymentOptions>,
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
impl SlotProvider {
|
|
@@ -66,12 +67,14 @@ impl SlotProvider {
|
|
|
66
67
|
task_queue: String,
|
|
67
68
|
wft_semaphore: MeteredPermitDealer<WorkflowSlotKind>,
|
|
68
69
|
external_wft_tx: WFTStreamSender,
|
|
70
|
+
deployment_options: Option<temporal_sdk_core_api::worker::WorkerDeploymentOptions>,
|
|
69
71
|
) -> Self {
|
|
70
72
|
Self {
|
|
71
73
|
namespace,
|
|
72
74
|
task_queue,
|
|
73
75
|
wft_semaphore,
|
|
74
76
|
external_wft_tx,
|
|
77
|
+
deployment_options,
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
}
|
|
@@ -89,6 +92,9 @@ impl SlotProviderTrait for SlotProvider {
|
|
|
89
92
|
None => None,
|
|
90
93
|
}
|
|
91
94
|
}
|
|
95
|
+
fn deployment_options(&self) -> Option<temporal_sdk_core_api::worker::WorkerDeploymentOptions> {
|
|
96
|
+
self.deployment_options.clone()
|
|
97
|
+
}
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
#[cfg(test)]
|
|
@@ -125,6 +131,7 @@ mod tests {
|
|
|
125
131
|
"my_queue".to_string(),
|
|
126
132
|
wft_semaphore,
|
|
127
133
|
external_wft_tx,
|
|
134
|
+
None,
|
|
128
135
|
);
|
|
129
136
|
|
|
130
137
|
let slot = provider
|
|
@@ -146,6 +153,7 @@ mod tests {
|
|
|
146
153
|
"my_queue".to_string(),
|
|
147
154
|
wft_semaphore,
|
|
148
155
|
external_wft_tx,
|
|
156
|
+
None,
|
|
149
157
|
);
|
|
150
158
|
assert!(provider.try_reserve_wft_slot().is_some());
|
|
151
159
|
}
|
|
@@ -163,6 +171,7 @@ mod tests {
|
|
|
163
171
|
"my_queue".to_string(),
|
|
164
172
|
wft_semaphore.clone(),
|
|
165
173
|
external_wft_tx,
|
|
174
|
+
None,
|
|
166
175
|
);
|
|
167
176
|
let slot = provider.try_reserve_wft_slot();
|
|
168
177
|
assert!(slot.is_some());
|
|
@@ -108,6 +108,24 @@ impl TunerHolderOptions {
|
|
|
108
108
|
}
|
|
109
109
|
None => {}
|
|
110
110
|
}
|
|
111
|
+
match self.nexus_slot_options {
|
|
112
|
+
Some(SlotSupplierOptions::FixedSize { slots }) => {
|
|
113
|
+
builder.nexus_slot_supplier(Arc::new(FixedSizeSlotSupplier::new(slots)));
|
|
114
|
+
}
|
|
115
|
+
Some(SlotSupplierOptions::ResourceBased(rso)) => {
|
|
116
|
+
builder.nexus_slot_supplier(
|
|
117
|
+
rb_tuner
|
|
118
|
+
.as_mut()
|
|
119
|
+
.unwrap()
|
|
120
|
+
.with_nexus_slots_options(rso)
|
|
121
|
+
.nexus_task_slot_supplier(),
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
Some(SlotSupplierOptions::Custom(ss)) => {
|
|
125
|
+
builder.nexus_slot_supplier(ss);
|
|
126
|
+
}
|
|
127
|
+
None => {}
|
|
128
|
+
}
|
|
111
129
|
Ok(builder.build())
|
|
112
130
|
}
|
|
113
131
|
}
|
|
@@ -144,6 +162,9 @@ impl TunerHolderOptionsBuilder {
|
|
|
144
162
|
) || matches!(
|
|
145
163
|
self.local_activity_slot_options,
|
|
146
164
|
Some(Some(SlotSupplierOptions::ResourceBased(_)))
|
|
165
|
+
) || matches!(
|
|
166
|
+
self.nexus_slot_options,
|
|
167
|
+
Some(Some(SlotSupplierOptions::ResourceBased(_)))
|
|
147
168
|
);
|
|
148
169
|
if any_is_resource_based && matches!(self.resource_based_options, None | Some(None)) {
|
|
149
170
|
return Err(
|
|
@@ -270,3 +291,141 @@ impl WorkerTuner for TunerHolder {
|
|
|
270
291
|
self.nexus_supplier.clone()
|
|
271
292
|
}
|
|
272
293
|
}
|
|
294
|
+
|
|
295
|
+
#[cfg(test)]
|
|
296
|
+
mod tests {
|
|
297
|
+
use super::*;
|
|
298
|
+
use std::time::Duration;
|
|
299
|
+
use temporal_sdk_core_api::worker::{
|
|
300
|
+
SlotMarkUsedContext, SlotReleaseContext, SlotReservationContext, SlotSupplierPermit,
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
struct TestSlotSupplier;
|
|
304
|
+
#[async_trait::async_trait]
|
|
305
|
+
impl SlotSupplier for TestSlotSupplier {
|
|
306
|
+
type SlotKind = NexusSlotKind;
|
|
307
|
+
async fn reserve_slot(&self, _: &dyn SlotReservationContext) -> SlotSupplierPermit {
|
|
308
|
+
SlotSupplierPermit::default()
|
|
309
|
+
}
|
|
310
|
+
fn try_reserve_slot(&self, _: &dyn SlotReservationContext) -> Option<SlotSupplierPermit> {
|
|
311
|
+
Some(SlotSupplierPermit::default())
|
|
312
|
+
}
|
|
313
|
+
fn mark_slot_used(&self, _: &dyn SlotMarkUsedContext<SlotKind = Self::SlotKind>) {}
|
|
314
|
+
fn release_slot(&self, _: &dyn SlotReleaseContext<SlotKind = Self::SlotKind>) {}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
#[test]
|
|
318
|
+
fn tuner_holder_options_nexus_fixed_size() {
|
|
319
|
+
let options = TunerHolderOptions {
|
|
320
|
+
workflow_slot_options: None,
|
|
321
|
+
activity_slot_options: None,
|
|
322
|
+
local_activity_slot_options: None,
|
|
323
|
+
nexus_slot_options: Some(SlotSupplierOptions::FixedSize { slots: 50 }),
|
|
324
|
+
resource_based_options: None,
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
let tuner = options.build_tuner_holder().unwrap();
|
|
328
|
+
// The tuner is built successfully with fixed size nexus slots
|
|
329
|
+
let _ = tuner.nexus_task_slot_supplier();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
#[test]
|
|
333
|
+
fn tuner_holder_options_nexus_resource_based() {
|
|
334
|
+
let resource_opts = ResourceBasedSlotsOptionsBuilder::default()
|
|
335
|
+
.target_mem_usage(0.8)
|
|
336
|
+
.target_cpu_usage(0.9)
|
|
337
|
+
.build()
|
|
338
|
+
.unwrap();
|
|
339
|
+
|
|
340
|
+
let options = TunerHolderOptions {
|
|
341
|
+
workflow_slot_options: None,
|
|
342
|
+
activity_slot_options: None,
|
|
343
|
+
local_activity_slot_options: None,
|
|
344
|
+
nexus_slot_options: Some(SlotSupplierOptions::ResourceBased(
|
|
345
|
+
ResourceSlotOptions::new(5, 100, Duration::from_millis(100)),
|
|
346
|
+
)),
|
|
347
|
+
resource_based_options: Some(resource_opts),
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
let tuner = options.build_tuner_holder().unwrap();
|
|
351
|
+
// The tuner is built successfully with resource-based nexus slots
|
|
352
|
+
let _ = tuner.nexus_task_slot_supplier();
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
#[test]
|
|
356
|
+
fn tuner_holder_options_nexus_custom() {
|
|
357
|
+
let custom_supplier: Arc<dyn SlotSupplier<SlotKind = NexusSlotKind> + Send + Sync> =
|
|
358
|
+
Arc::new(TestSlotSupplier);
|
|
359
|
+
|
|
360
|
+
let options = TunerHolderOptions {
|
|
361
|
+
workflow_slot_options: None,
|
|
362
|
+
activity_slot_options: None,
|
|
363
|
+
local_activity_slot_options: None,
|
|
364
|
+
nexus_slot_options: Some(SlotSupplierOptions::Custom(custom_supplier.clone())),
|
|
365
|
+
resource_based_options: None,
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
let tuner = options.build_tuner_holder().unwrap();
|
|
369
|
+
// The tuner is built successfully with custom nexus slots
|
|
370
|
+
let _ = tuner.nexus_task_slot_supplier();
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
#[test]
|
|
374
|
+
fn tuner_builder_with_nexus_slot_supplier() {
|
|
375
|
+
let mut builder = TunerBuilder::default();
|
|
376
|
+
let custom_supplier: Arc<dyn SlotSupplier<SlotKind = NexusSlotKind> + Send + Sync> =
|
|
377
|
+
Arc::new(FixedSizeSlotSupplier::new(25));
|
|
378
|
+
|
|
379
|
+
builder.nexus_slot_supplier(custom_supplier.clone());
|
|
380
|
+
let tuner = builder.build();
|
|
381
|
+
|
|
382
|
+
// The tuner is built successfully with the custom nexus slot supplier
|
|
383
|
+
let _ = tuner.nexus_task_slot_supplier();
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
#[test]
|
|
387
|
+
fn tuner_holder_options_builder_validates_resource_based_requirements() {
|
|
388
|
+
// Should fail when nexus uses ResourceBased but resource_based_options is not set
|
|
389
|
+
let result = TunerHolderOptionsBuilder::default()
|
|
390
|
+
.nexus_slot_options(SlotSupplierOptions::ResourceBased(
|
|
391
|
+
ResourceSlotOptions::new(5, 100, Duration::from_millis(100)),
|
|
392
|
+
))
|
|
393
|
+
.build();
|
|
394
|
+
|
|
395
|
+
assert!(result.is_err());
|
|
396
|
+
assert!(
|
|
397
|
+
result
|
|
398
|
+
.unwrap_err()
|
|
399
|
+
.to_string()
|
|
400
|
+
.contains("resource_based_options")
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
#[test]
|
|
405
|
+
fn tuner_holder_options_all_slot_types() {
|
|
406
|
+
let resource_opts = ResourceBasedSlotsOptionsBuilder::default()
|
|
407
|
+
.target_mem_usage(0.8)
|
|
408
|
+
.target_cpu_usage(0.9)
|
|
409
|
+
.build()
|
|
410
|
+
.unwrap();
|
|
411
|
+
|
|
412
|
+
let options = TunerHolderOptions {
|
|
413
|
+
workflow_slot_options: Some(SlotSupplierOptions::FixedSize { slots: 10 }),
|
|
414
|
+
activity_slot_options: Some(SlotSupplierOptions::FixedSize { slots: 20 }),
|
|
415
|
+
local_activity_slot_options: Some(SlotSupplierOptions::ResourceBased(
|
|
416
|
+
ResourceSlotOptions::new(2, 50, Duration::from_millis(100)),
|
|
417
|
+
)),
|
|
418
|
+
nexus_slot_options: Some(SlotSupplierOptions::ResourceBased(
|
|
419
|
+
ResourceSlotOptions::new(5, 100, Duration::from_millis(100)),
|
|
420
|
+
)),
|
|
421
|
+
resource_based_options: Some(resource_opts),
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
let tuner = options.build_tuner_holder().unwrap();
|
|
425
|
+
// All suppliers should be successfully configured
|
|
426
|
+
let _ = tuner.workflow_task_slot_supplier();
|
|
427
|
+
let _ = tuner.activity_task_slot_supplier();
|
|
428
|
+
let _ = tuner.local_activity_slot_supplier();
|
|
429
|
+
let _ = tuner.nexus_task_slot_supplier();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
@@ -806,15 +806,12 @@ mod tests {
|
|
|
806
806
|
use super::*;
|
|
807
807
|
use crate::{
|
|
808
808
|
replay::{HistoryInfo, TestHistoryBuilder},
|
|
809
|
-
test_help::{
|
|
809
|
+
test_help::{ResponseType, hist_to_poll_resp},
|
|
810
810
|
worker::client::mocks::mock_worker_client,
|
|
811
811
|
};
|
|
812
|
-
use futures_util::
|
|
813
|
-
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
814
|
-
use temporal_client::WorkflowOptions;
|
|
815
|
-
use temporal_sdk::WfContext;
|
|
812
|
+
use futures_util::TryStreamExt;
|
|
816
813
|
use temporal_sdk_core_protos::{
|
|
817
|
-
|
|
814
|
+
canned_histories,
|
|
818
815
|
temporal::api::{
|
|
819
816
|
common::v1::WorkflowExecution, enums::v1::WorkflowTaskFailedCause,
|
|
820
817
|
workflowservice::v1::GetWorkflowExecutionHistoryResponse,
|
|
@@ -1334,124 +1331,6 @@ mod tests {
|
|
|
1334
1331
|
assert_matches!(update.take_next_wft_sequence(8), NextWFT::ReplayOver);
|
|
1335
1332
|
}
|
|
1336
1333
|
|
|
1337
|
-
#[tokio::test]
|
|
1338
|
-
async fn weird_pagination_doesnt_drop_wft_events() {
|
|
1339
|
-
let wf_id = "fakeid";
|
|
1340
|
-
// 1: EVENT_TYPE_WORKFLOW_EXECUTION_STARTED
|
|
1341
|
-
// 2: EVENT_TYPE_WORKFLOW_TASK_SCHEDULED
|
|
1342
|
-
// 3: EVENT_TYPE_WORKFLOW_TASK_STARTED
|
|
1343
|
-
// 4: EVENT_TYPE_WORKFLOW_TASK_COMPLETED
|
|
1344
|
-
// empty page
|
|
1345
|
-
// 5: EVENT_TYPE_WORKFLOW_EXECUTION_SIGNALED
|
|
1346
|
-
// 6: EVENT_TYPE_WORKFLOW_TASK_SCHEDULED
|
|
1347
|
-
// 7: EVENT_TYPE_WORKFLOW_TASK_STARTED
|
|
1348
|
-
// 8: EVENT_TYPE_WORKFLOW_TASK_FAILED
|
|
1349
|
-
// empty page
|
|
1350
|
-
// 9: EVENT_TYPE_WORKFLOW_EXECUTION_SIGNALED
|
|
1351
|
-
// 10: EVENT_TYPE_WORKFLOW_TASK_SCHEDULED
|
|
1352
|
-
// 11: EVENT_TYPE_WORKFLOW_TASK_STARTED
|
|
1353
|
-
// empty page
|
|
1354
|
-
let mut t = TestHistoryBuilder::default();
|
|
1355
|
-
t.add_by_type(EventType::WorkflowExecutionStarted);
|
|
1356
|
-
t.add_full_wf_task();
|
|
1357
|
-
|
|
1358
|
-
t.add_we_signaled("hi", vec![]);
|
|
1359
|
-
t.add_workflow_task_scheduled_and_started();
|
|
1360
|
-
t.add_workflow_task_failed_with_failure(
|
|
1361
|
-
WorkflowTaskFailedCause::UnhandledCommand,
|
|
1362
|
-
Default::default(),
|
|
1363
|
-
);
|
|
1364
|
-
|
|
1365
|
-
t.add_we_signaled("hi", vec![]);
|
|
1366
|
-
t.add_workflow_task_scheduled_and_started();
|
|
1367
|
-
|
|
1368
|
-
let workflow_task = t.get_full_history_info().unwrap();
|
|
1369
|
-
let mut wft_resp = workflow_task.as_poll_wft_response();
|
|
1370
|
-
wft_resp.workflow_execution = Some(WorkflowExecution {
|
|
1371
|
-
workflow_id: wf_id.to_string(),
|
|
1372
|
-
run_id: t.get_orig_run_id().to_string(),
|
|
1373
|
-
});
|
|
1374
|
-
// Just 9/10/11 in WFT
|
|
1375
|
-
wft_resp.history.as_mut().unwrap().events.drain(0..8);
|
|
1376
|
-
|
|
1377
|
-
let mut resp_1: GetWorkflowExecutionHistoryResponse =
|
|
1378
|
-
t.get_full_history_info().unwrap().into();
|
|
1379
|
-
resp_1.next_page_token = vec![1];
|
|
1380
|
-
resp_1.history.as_mut().unwrap().events.truncate(4);
|
|
1381
|
-
|
|
1382
|
-
let mut mock_client = mock_worker_client();
|
|
1383
|
-
mock_client
|
|
1384
|
-
.expect_get_workflow_execution_history()
|
|
1385
|
-
.returning(move |_, _, _| Ok(resp_1.clone()))
|
|
1386
|
-
.times(1);
|
|
1387
|
-
mock_client
|
|
1388
|
-
.expect_get_workflow_execution_history()
|
|
1389
|
-
.returning(move |_, _, _| {
|
|
1390
|
-
Ok(GetWorkflowExecutionHistoryResponse {
|
|
1391
|
-
history: Some(History { events: vec![] }),
|
|
1392
|
-
raw_history: vec![],
|
|
1393
|
-
next_page_token: vec![2],
|
|
1394
|
-
archived: false,
|
|
1395
|
-
})
|
|
1396
|
-
})
|
|
1397
|
-
.times(1);
|
|
1398
|
-
let mut resp_2: GetWorkflowExecutionHistoryResponse =
|
|
1399
|
-
t.get_full_history_info().unwrap().into();
|
|
1400
|
-
resp_2.next_page_token = vec![3];
|
|
1401
|
-
resp_2.history.as_mut().unwrap().events.drain(0..4);
|
|
1402
|
-
resp_2.history.as_mut().unwrap().events.truncate(4);
|
|
1403
|
-
mock_client
|
|
1404
|
-
.expect_get_workflow_execution_history()
|
|
1405
|
-
.returning(move |_, _, _| Ok(resp_2.clone()))
|
|
1406
|
-
.times(1);
|
|
1407
|
-
mock_client
|
|
1408
|
-
.expect_get_workflow_execution_history()
|
|
1409
|
-
.returning(move |_, _, _| {
|
|
1410
|
-
Ok(GetWorkflowExecutionHistoryResponse {
|
|
1411
|
-
history: Some(History { events: vec![] }),
|
|
1412
|
-
raw_history: vec![],
|
|
1413
|
-
next_page_token: vec![],
|
|
1414
|
-
archived: false,
|
|
1415
|
-
})
|
|
1416
|
-
})
|
|
1417
|
-
.times(1);
|
|
1418
|
-
|
|
1419
|
-
let wf_type = DEFAULT_WORKFLOW_TYPE;
|
|
1420
|
-
let mh =
|
|
1421
|
-
MockPollCfg::from_resp_batches(wf_id, t, [ResponseType::Raw(wft_resp)], mock_client);
|
|
1422
|
-
let mut worker = mock_sdk_cfg(mh, |cfg| {
|
|
1423
|
-
cfg.max_cached_workflows = 2;
|
|
1424
|
-
cfg.ignore_evicts_on_shutdown = false;
|
|
1425
|
-
});
|
|
1426
|
-
|
|
1427
|
-
let sig_ctr = Arc::new(AtomicUsize::new(0));
|
|
1428
|
-
let sig_ctr_clone = sig_ctr.clone();
|
|
1429
|
-
worker.register_wf(wf_type.to_owned(), move |ctx: WfContext| {
|
|
1430
|
-
let sig_ctr_clone = sig_ctr_clone.clone();
|
|
1431
|
-
async move {
|
|
1432
|
-
let mut sigchan = ctx.make_signal_channel("hi");
|
|
1433
|
-
while sigchan.next().await.is_some() {
|
|
1434
|
-
if sig_ctr_clone.fetch_add(1, Ordering::AcqRel) == 1 {
|
|
1435
|
-
break;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
Ok(().into())
|
|
1439
|
-
}
|
|
1440
|
-
});
|
|
1441
|
-
|
|
1442
|
-
worker
|
|
1443
|
-
.submit_wf(
|
|
1444
|
-
wf_id.to_owned(),
|
|
1445
|
-
wf_type.to_owned(),
|
|
1446
|
-
vec![],
|
|
1447
|
-
WorkflowOptions::default(),
|
|
1448
|
-
)
|
|
1449
|
-
.await
|
|
1450
|
-
.unwrap();
|
|
1451
|
-
worker.run_until_done().await.unwrap();
|
|
1452
|
-
assert_eq!(sig_ctr.load(Ordering::Acquire), 2);
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
1334
|
#[tokio::test]
|
|
1456
1335
|
async fn extreme_pagination_doesnt_drop_wft_events_paginator() {
|
|
1457
1336
|
// 1: EVENT_TYPE_WORKFLOW_EXECUTION_STARTED
|
|
@@ -1559,147 +1438,6 @@ mod tests {
|
|
|
1559
1438
|
assert_eq!(seq.last().unwrap().event_id, 15);
|
|
1560
1439
|
}
|
|
1561
1440
|
|
|
1562
|
-
#[tokio::test]
|
|
1563
|
-
async fn extreme_pagination_doesnt_drop_wft_events_worker() {
|
|
1564
|
-
let wf_id = "fakeid";
|
|
1565
|
-
|
|
1566
|
-
// In this test, we add empty pages between each event
|
|
1567
|
-
|
|
1568
|
-
// 1: EVENT_TYPE_WORKFLOW_EXECUTION_STARTED
|
|
1569
|
-
// 2: EVENT_TYPE_WORKFLOW_TASK_SCHEDULED
|
|
1570
|
-
// 3: EVENT_TYPE_WORKFLOW_TASK_STARTED // <- previous_started_event_id
|
|
1571
|
-
// 4: EVENT_TYPE_WORKFLOW_TASK_COMPLETED
|
|
1572
|
-
|
|
1573
|
-
// 5: EVENT_TYPE_WORKFLOW_EXECUTION_SIGNALED
|
|
1574
|
-
// 6: EVENT_TYPE_WORKFLOW_TASK_SCHEDULED
|
|
1575
|
-
// 7: EVENT_TYPE_WORKFLOW_TASK_STARTED
|
|
1576
|
-
// 8: EVENT_TYPE_WORKFLOW_TASK_FAILED
|
|
1577
|
-
|
|
1578
|
-
// 9: EVENT_TYPE_WORKFLOW_EXECUTION_SIGNALED
|
|
1579
|
-
// 10: EVENT_TYPE_WORKFLOW_EXECUTION_SIGNALED
|
|
1580
|
-
// 11: EVENT_TYPE_WORKFLOW_EXECUTION_SIGNALED
|
|
1581
|
-
// 12: EVENT_TYPE_WORKFLOW_EXECUTION_SIGNALED
|
|
1582
|
-
// 13: EVENT_TYPE_WORKFLOW_EXECUTION_SIGNALED
|
|
1583
|
-
// 14: EVENT_TYPE_WORKFLOW_TASK_SCHEDULED
|
|
1584
|
-
// 15: EVENT_TYPE_WORKFLOW_TASK_STARTED // <- started_event_id
|
|
1585
|
-
|
|
1586
|
-
let mut t = TestHistoryBuilder::default();
|
|
1587
|
-
t.add_by_type(EventType::WorkflowExecutionStarted);
|
|
1588
|
-
t.add_full_wf_task();
|
|
1589
|
-
|
|
1590
|
-
t.add_we_signaled("hi", vec![]);
|
|
1591
|
-
t.add_workflow_task_scheduled_and_started();
|
|
1592
|
-
t.add_workflow_task_failed_with_failure(
|
|
1593
|
-
WorkflowTaskFailedCause::UnhandledCommand,
|
|
1594
|
-
Default::default(),
|
|
1595
|
-
);
|
|
1596
|
-
|
|
1597
|
-
t.add_we_signaled("hi", vec![]);
|
|
1598
|
-
t.add_we_signaled("hi", vec![]);
|
|
1599
|
-
t.add_we_signaled("hi", vec![]);
|
|
1600
|
-
t.add_we_signaled("hi", vec![]);
|
|
1601
|
-
t.add_we_signaled("hi", vec![]);
|
|
1602
|
-
t.add_workflow_task_scheduled_and_started();
|
|
1603
|
-
|
|
1604
|
-
/////
|
|
1605
|
-
|
|
1606
|
-
let events: Vec<HistoryEvent> = t.get_full_history_info().unwrap().into_events();
|
|
1607
|
-
let first_event = events[0].clone();
|
|
1608
|
-
|
|
1609
|
-
let mut mock_client = mock_worker_client();
|
|
1610
|
-
|
|
1611
|
-
for (i, event) in events.into_iter().enumerate() {
|
|
1612
|
-
// Add an empty page
|
|
1613
|
-
mock_client
|
|
1614
|
-
.expect_get_workflow_execution_history()
|
|
1615
|
-
.returning(move |_, _, _| {
|
|
1616
|
-
Ok(GetWorkflowExecutionHistoryResponse {
|
|
1617
|
-
history: Some(History { events: vec![] }),
|
|
1618
|
-
raw_history: vec![],
|
|
1619
|
-
next_page_token: vec![(i * 10 + 1) as u8],
|
|
1620
|
-
archived: false,
|
|
1621
|
-
})
|
|
1622
|
-
})
|
|
1623
|
-
.times(1);
|
|
1624
|
-
|
|
1625
|
-
// Add a page with just event i
|
|
1626
|
-
mock_client
|
|
1627
|
-
.expect_get_workflow_execution_history()
|
|
1628
|
-
.returning(move |_, _, _| {
|
|
1629
|
-
Ok(GetWorkflowExecutionHistoryResponse {
|
|
1630
|
-
history: Some(History {
|
|
1631
|
-
events: vec![event.clone()],
|
|
1632
|
-
}),
|
|
1633
|
-
raw_history: vec![],
|
|
1634
|
-
next_page_token: vec![(i * 10) as u8],
|
|
1635
|
-
archived: false,
|
|
1636
|
-
})
|
|
1637
|
-
})
|
|
1638
|
-
.times(1);
|
|
1639
|
-
}
|
|
1640
|
-
|
|
1641
|
-
// Add an extra empty page at the end, with no NPT
|
|
1642
|
-
mock_client
|
|
1643
|
-
.expect_get_workflow_execution_history()
|
|
1644
|
-
.returning(move |_, _, _| {
|
|
1645
|
-
Ok(GetWorkflowExecutionHistoryResponse {
|
|
1646
|
-
history: Some(History { events: vec![] }),
|
|
1647
|
-
raw_history: vec![],
|
|
1648
|
-
next_page_token: vec![],
|
|
1649
|
-
archived: false,
|
|
1650
|
-
})
|
|
1651
|
-
})
|
|
1652
|
-
.times(1);
|
|
1653
|
-
|
|
1654
|
-
let workflow_task = t.get_full_history_info().unwrap();
|
|
1655
|
-
let mut wft_resp = workflow_task.as_poll_wft_response();
|
|
1656
|
-
wft_resp.workflow_execution = Some(WorkflowExecution {
|
|
1657
|
-
workflow_id: wf_id.to_string(),
|
|
1658
|
-
run_id: t.get_orig_run_id().to_string(),
|
|
1659
|
-
});
|
|
1660
|
-
wft_resp.history = Some(History {
|
|
1661
|
-
events: vec![first_event],
|
|
1662
|
-
});
|
|
1663
|
-
wft_resp.next_page_token = vec![1];
|
|
1664
|
-
wft_resp.previous_started_event_id = 3;
|
|
1665
|
-
wft_resp.started_event_id = 15;
|
|
1666
|
-
|
|
1667
|
-
let wf_type = DEFAULT_WORKFLOW_TYPE;
|
|
1668
|
-
let mh =
|
|
1669
|
-
MockPollCfg::from_resp_batches(wf_id, t, [ResponseType::Raw(wft_resp)], mock_client);
|
|
1670
|
-
let mut worker = mock_sdk_cfg(mh, |cfg| {
|
|
1671
|
-
cfg.max_cached_workflows = 2;
|
|
1672
|
-
cfg.ignore_evicts_on_shutdown = false;
|
|
1673
|
-
});
|
|
1674
|
-
|
|
1675
|
-
let sig_ctr = Arc::new(AtomicUsize::new(0));
|
|
1676
|
-
let sig_ctr_clone = sig_ctr.clone();
|
|
1677
|
-
worker.register_wf(wf_type.to_owned(), move |ctx: WfContext| {
|
|
1678
|
-
let sig_ctr_clone = sig_ctr_clone.clone();
|
|
1679
|
-
async move {
|
|
1680
|
-
let mut sigchan = ctx.make_signal_channel("hi");
|
|
1681
|
-
while sigchan.next().await.is_some() {
|
|
1682
|
-
if sig_ctr_clone.fetch_add(1, Ordering::AcqRel) == 5 {
|
|
1683
|
-
break;
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
Ok(().into())
|
|
1687
|
-
}
|
|
1688
|
-
});
|
|
1689
|
-
|
|
1690
|
-
worker
|
|
1691
|
-
.submit_wf(
|
|
1692
|
-
wf_id.to_owned(),
|
|
1693
|
-
wf_type.to_owned(),
|
|
1694
|
-
vec![],
|
|
1695
|
-
WorkflowOptions::default(),
|
|
1696
|
-
)
|
|
1697
|
-
.await
|
|
1698
|
-
.unwrap();
|
|
1699
|
-
worker.run_until_done().await.unwrap();
|
|
1700
|
-
assert_eq!(sig_ctr.load(Ordering::Acquire), 6);
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1703
1441
|
#[tokio::test]
|
|
1704
1442
|
async fn finding_end_index_with_started_as_last_event() {
|
|
1705
1443
|
let wf_id = "fakeid";
|
|
@@ -803,63 +803,10 @@ mod test {
|
|
|
803
803
|
use super::*;
|
|
804
804
|
use crate::{
|
|
805
805
|
internal_flags::InternalFlags,
|
|
806
|
-
replay::TestHistoryBuilder,
|
|
807
|
-
test_help::{MockPollCfg, ResponseType, build_fake_sdk},
|
|
808
806
|
worker::workflow::{OutgoingJob, machines::Machines},
|
|
809
807
|
};
|
|
810
808
|
use std::{cell::RefCell, mem::discriminant, rc::Rc};
|
|
811
|
-
use
|
|
812
|
-
use temporal_sdk_core_protos::{
|
|
813
|
-
DEFAULT_WORKFLOW_TYPE,
|
|
814
|
-
coresdk::workflow_activation::{WorkflowActivationJob, workflow_activation_job},
|
|
815
|
-
};
|
|
816
|
-
use temporal_sdk_core_test_utils::interceptors::ActivationAssertionsInterceptor;
|
|
817
|
-
|
|
818
|
-
#[tokio::test]
|
|
819
|
-
async fn immediate_activity_cancelation() {
|
|
820
|
-
let func = WorkflowFunction::new(|ctx: WfContext| async move {
|
|
821
|
-
let cancel_activity_future = ctx.activity(ActivityOptions::default());
|
|
822
|
-
// Immediately cancel the activity
|
|
823
|
-
cancel_activity_future.cancel(&ctx);
|
|
824
|
-
cancel_activity_future.await;
|
|
825
|
-
Ok(().into())
|
|
826
|
-
});
|
|
827
|
-
|
|
828
|
-
let mut t = TestHistoryBuilder::default();
|
|
829
|
-
t.add_by_type(EventType::WorkflowExecutionStarted);
|
|
830
|
-
t.add_full_wf_task();
|
|
831
|
-
t.add_workflow_execution_completed();
|
|
832
|
-
let mut worker = build_fake_sdk(MockPollCfg::from_resps(t, [ResponseType::AllHistory]));
|
|
833
|
-
worker.register_wf(DEFAULT_WORKFLOW_TYPE, func);
|
|
834
|
-
|
|
835
|
-
let mut aai = ActivationAssertionsInterceptor::default();
|
|
836
|
-
aai.then(|a| {
|
|
837
|
-
assert_matches!(
|
|
838
|
-
a.jobs.as_slice(),
|
|
839
|
-
[WorkflowActivationJob {
|
|
840
|
-
variant: Some(workflow_activation_job::Variant::InitializeWorkflow(_)),
|
|
841
|
-
}]
|
|
842
|
-
)
|
|
843
|
-
});
|
|
844
|
-
aai.then(|a| {
|
|
845
|
-
assert_matches!(
|
|
846
|
-
a.jobs.as_slice(),
|
|
847
|
-
[WorkflowActivationJob {
|
|
848
|
-
variant: Some(workflow_activation_job::Variant::ResolveActivity(
|
|
849
|
-
ResolveActivity {
|
|
850
|
-
result: Some(ActivityResolution {
|
|
851
|
-
status: Some(activity_resolution::Status::Cancelled(_))
|
|
852
|
-
}),
|
|
853
|
-
..
|
|
854
|
-
}
|
|
855
|
-
)),
|
|
856
|
-
},]
|
|
857
|
-
)
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
worker.set_worker_interceptor(aai);
|
|
861
|
-
worker.run().await.unwrap();
|
|
862
|
-
}
|
|
809
|
+
use temporal_sdk_core_protos::coresdk::workflow_activation::workflow_activation_job;
|
|
863
810
|
|
|
864
811
|
#[test]
|
|
865
812
|
fn cancels_ignored_terminal() {
|
|
@@ -210,85 +210,3 @@ impl WFMachinesAdapter for CancelExternalMachine {
|
|
|
210
210
|
})
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
|
-
|
|
214
|
-
#[cfg(test)]
|
|
215
|
-
mod tests {
|
|
216
|
-
use super::*;
|
|
217
|
-
use crate::{
|
|
218
|
-
replay::TestHistoryBuilder,
|
|
219
|
-
test_help::{MockPollCfg, build_fake_sdk},
|
|
220
|
-
};
|
|
221
|
-
use temporal_sdk::{WfContext, WorkflowResult};
|
|
222
|
-
use temporal_sdk_core_protos::DEFAULT_WORKFLOW_TYPE;
|
|
223
|
-
|
|
224
|
-
async fn cancel_sender(ctx: WfContext) -> WorkflowResult<()> {
|
|
225
|
-
let res = ctx
|
|
226
|
-
.cancel_external(
|
|
227
|
-
NamespacedWorkflowExecution {
|
|
228
|
-
namespace: "some_namespace".to_string(),
|
|
229
|
-
workflow_id: "fake_wid".to_string(),
|
|
230
|
-
run_id: "fake_rid".to_string(),
|
|
231
|
-
},
|
|
232
|
-
"cancel reason".to_string(),
|
|
233
|
-
)
|
|
234
|
-
.await;
|
|
235
|
-
if res.is_err() {
|
|
236
|
-
Err(anyhow::anyhow!("Cancel fail!"))
|
|
237
|
-
} else {
|
|
238
|
-
Ok(().into())
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
#[rstest::rstest]
|
|
243
|
-
#[case::succeeds(false)]
|
|
244
|
-
#[case::fails(true)]
|
|
245
|
-
#[tokio::test]
|
|
246
|
-
async fn sends_cancel(#[case] fails: bool) {
|
|
247
|
-
let mut t = TestHistoryBuilder::default();
|
|
248
|
-
t.add_by_type(EventType::WorkflowExecutionStarted);
|
|
249
|
-
t.add_full_wf_task();
|
|
250
|
-
let id = t.add_cancel_external_wf(NamespacedWorkflowExecution {
|
|
251
|
-
namespace: "some_namespace".to_string(),
|
|
252
|
-
workflow_id: "fake_wid".to_string(),
|
|
253
|
-
run_id: "fake_rid".to_string(),
|
|
254
|
-
});
|
|
255
|
-
if fails {
|
|
256
|
-
t.add_cancel_external_wf_failed(id);
|
|
257
|
-
} else {
|
|
258
|
-
t.add_cancel_external_wf_completed(id);
|
|
259
|
-
}
|
|
260
|
-
t.add_full_wf_task();
|
|
261
|
-
if fails {
|
|
262
|
-
t.add_workflow_execution_failed();
|
|
263
|
-
} else {
|
|
264
|
-
t.add_workflow_execution_completed();
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
let mut mock_cfg = MockPollCfg::from_hist_builder(t);
|
|
268
|
-
mock_cfg.completion_asserts_from_expectations(|mut asserts| {
|
|
269
|
-
asserts
|
|
270
|
-
.then(|wft| {
|
|
271
|
-
assert_matches!(
|
|
272
|
-
wft.commands[0].command_type(),
|
|
273
|
-
CommandType::RequestCancelExternalWorkflowExecution
|
|
274
|
-
);
|
|
275
|
-
})
|
|
276
|
-
.then(move |wft| {
|
|
277
|
-
if fails {
|
|
278
|
-
assert_eq!(
|
|
279
|
-
wft.commands[0].command_type(),
|
|
280
|
-
CommandType::FailWorkflowExecution
|
|
281
|
-
);
|
|
282
|
-
} else {
|
|
283
|
-
assert_eq!(
|
|
284
|
-
wft.commands[0].command_type(),
|
|
285
|
-
CommandType::CompleteWorkflowExecution
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
let mut worker = build_fake_sdk(mock_cfg);
|
|
291
|
-
worker.register_wf(DEFAULT_WORKFLOW_TYPE, cancel_sender);
|
|
292
|
-
worker.run().await.unwrap();
|
|
293
|
-
}
|
|
294
|
-
}
|