temporalio 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Cargo.lock +4035 -0
- data/Cargo.toml +25 -0
- data/Gemfile +20 -0
- data/LICENSE +16 -15
- data/README.md +455 -195
- data/Rakefile +387 -0
- data/ext/Cargo.toml +25 -0
- data/lib/temporalio/activity/complete_async_error.rb +11 -0
- data/lib/temporalio/activity/context.rb +82 -77
- data/lib/temporalio/activity/definition.rb +77 -0
- data/lib/temporalio/activity/info.rb +42 -46
- data/lib/temporalio/activity.rb +49 -65
- data/lib/temporalio/api/batch/v1/message.rb +31 -0
- data/lib/temporalio/api/cloud/cloudservice/v1/request_response.rb +93 -0
- data/lib/temporalio/api/cloud/cloudservice/v1/service.rb +25 -0
- data/lib/temporalio/api/cloud/cloudservice.rb +3 -0
- data/lib/temporalio/api/cloud/identity/v1/message.rb +36 -0
- data/lib/temporalio/api/cloud/namespace/v1/message.rb +35 -0
- data/lib/temporalio/api/cloud/operation/v1/message.rb +27 -0
- data/lib/temporalio/api/cloud/region/v1/message.rb +23 -0
- data/lib/temporalio/api/command/v1/message.rb +46 -0
- data/lib/temporalio/api/common/v1/grpc_status.rb +23 -0
- data/lib/temporalio/api/common/v1/message.rb +41 -0
- data/lib/temporalio/api/enums/v1/batch_operation.rb +22 -0
- data/lib/temporalio/api/enums/v1/command_type.rb +21 -0
- data/lib/temporalio/api/enums/v1/common.rb +26 -0
- data/lib/temporalio/api/enums/v1/event_type.rb +21 -0
- data/lib/temporalio/api/enums/v1/failed_cause.rb +26 -0
- data/lib/temporalio/api/enums/v1/namespace.rb +23 -0
- data/lib/temporalio/api/enums/v1/query.rb +22 -0
- data/lib/temporalio/api/enums/v1/reset.rb +23 -0
- data/lib/temporalio/api/enums/v1/schedule.rb +21 -0
- data/lib/temporalio/api/enums/v1/task_queue.rb +25 -0
- data/lib/temporalio/api/enums/v1/update.rb +22 -0
- data/lib/temporalio/api/enums/v1/workflow.rb +30 -0
- data/lib/temporalio/api/errordetails/v1/message.rb +42 -0
- data/lib/temporalio/api/export/v1/message.rb +24 -0
- data/lib/temporalio/api/failure/v1/message.rb +35 -0
- data/lib/temporalio/api/filter/v1/message.rb +27 -0
- data/lib/temporalio/api/history/v1/message.rb +90 -0
- data/lib/temporalio/api/namespace/v1/message.rb +31 -0
- data/lib/temporalio/api/nexus/v1/message.rb +40 -0
- data/lib/temporalio/api/operatorservice/v1/request_response.rb +49 -0
- data/lib/temporalio/api/operatorservice/v1/service.rb +23 -0
- data/lib/temporalio/api/operatorservice.rb +3 -0
- data/lib/temporalio/api/protocol/v1/message.rb +23 -0
- data/lib/temporalio/api/query/v1/message.rb +27 -0
- data/lib/temporalio/api/replication/v1/message.rb +26 -0
- data/lib/temporalio/api/schedule/v1/message.rb +42 -0
- data/lib/temporalio/api/sdk/v1/enhanced_stack_trace.rb +25 -0
- data/lib/temporalio/api/sdk/v1/task_complete_metadata.rb +21 -0
- data/lib/temporalio/api/sdk/v1/user_metadata.rb +23 -0
- data/lib/temporalio/api/sdk/v1/workflow_metadata.rb +23 -0
- data/lib/temporalio/api/taskqueue/v1/message.rb +45 -0
- data/lib/temporalio/api/update/v1/message.rb +33 -0
- data/lib/temporalio/api/version/v1/message.rb +26 -0
- data/lib/temporalio/api/workflow/v1/message.rb +43 -0
- data/lib/temporalio/api/workflowservice/v1/request_response.rb +189 -0
- data/lib/temporalio/api/workflowservice/v1/service.rb +23 -0
- data/lib/temporalio/api/workflowservice.rb +3 -0
- data/lib/temporalio/api.rb +13 -0
- data/lib/temporalio/cancellation.rb +150 -0
- data/lib/temporalio/client/activity_id_reference.rb +32 -0
- data/lib/temporalio/client/async_activity_handle.rb +110 -0
- data/lib/temporalio/client/connection/cloud_service.rb +648 -0
- data/lib/temporalio/client/connection/operator_service.rb +249 -0
- data/lib/temporalio/client/connection/service.rb +41 -0
- data/lib/temporalio/client/connection/workflow_service.rb +1218 -0
- data/lib/temporalio/client/connection.rb +270 -0
- data/lib/temporalio/client/interceptor.rb +316 -0
- data/lib/temporalio/client/workflow_execution.rb +103 -0
- data/lib/temporalio/client/workflow_execution_count.rb +36 -0
- data/lib/temporalio/client/workflow_execution_status.rb +18 -0
- data/lib/temporalio/client/workflow_handle.rb +380 -177
- data/lib/temporalio/client/workflow_query_reject_condition.rb +14 -0
- data/lib/temporalio/client/workflow_update_handle.rb +67 -0
- data/lib/temporalio/client/workflow_update_wait_stage.rb +17 -0
- data/lib/temporalio/client.rb +366 -93
- data/lib/temporalio/common_enums.rb +24 -0
- data/lib/temporalio/converters/data_converter.rb +102 -0
- data/lib/temporalio/converters/failure_converter.rb +200 -0
- data/lib/temporalio/converters/payload_codec.rb +26 -0
- data/lib/temporalio/converters/payload_converter/binary_null.rb +34 -0
- data/lib/temporalio/converters/payload_converter/binary_plain.rb +35 -0
- data/lib/temporalio/converters/payload_converter/binary_protobuf.rb +42 -0
- data/lib/temporalio/converters/payload_converter/composite.rb +62 -0
- data/lib/temporalio/converters/payload_converter/encoding.rb +35 -0
- data/lib/temporalio/converters/payload_converter/json_plain.rb +44 -0
- data/lib/temporalio/converters/payload_converter/json_protobuf.rb +41 -0
- data/lib/temporalio/converters/payload_converter.rb +73 -0
- data/lib/temporalio/converters.rb +9 -0
- data/lib/temporalio/error/failure.rb +119 -94
- data/lib/temporalio/error.rb +147 -0
- data/lib/temporalio/internal/bridge/api/activity_result/activity_result.rb +34 -0
- data/lib/temporalio/internal/bridge/api/activity_task/activity_task.rb +31 -0
- data/lib/temporalio/internal/bridge/api/child_workflow/child_workflow.rb +33 -0
- data/lib/temporalio/internal/bridge/api/common/common.rb +26 -0
- data/lib/temporalio/internal/bridge/api/core_interface.rb +36 -0
- data/lib/temporalio/internal/bridge/api/external_data/external_data.rb +27 -0
- data/lib/temporalio/internal/bridge/api/workflow_activation/workflow_activation.rb +52 -0
- data/lib/temporalio/internal/bridge/api/workflow_commands/workflow_commands.rb +54 -0
- data/lib/temporalio/internal/bridge/api/workflow_completion/workflow_completion.rb +30 -0
- data/lib/temporalio/internal/bridge/api.rb +3 -0
- data/lib/temporalio/internal/bridge/client.rb +90 -0
- data/lib/temporalio/internal/bridge/runtime.rb +53 -0
- data/lib/temporalio/internal/bridge/testing.rb +46 -0
- data/lib/temporalio/internal/bridge/worker.rb +83 -0
- data/lib/temporalio/internal/bridge.rb +36 -0
- data/lib/temporalio/internal/client/implementation.rb +525 -0
- data/lib/temporalio/internal/proto_utils.rb +54 -0
- data/lib/temporalio/internal/worker/activity_worker.rb +345 -0
- data/lib/temporalio/internal/worker/multi_runner.rb +169 -0
- data/lib/temporalio/internal.rb +7 -0
- data/lib/temporalio/retry_policy.rb +39 -80
- data/lib/temporalio/runtime.rb +259 -13
- data/lib/temporalio/scoped_logger.rb +96 -0
- data/lib/temporalio/search_attributes.rb +300 -0
- data/lib/temporalio/testing/activity_environment.rb +132 -0
- data/lib/temporalio/testing/workflow_environment.rb +113 -88
- data/lib/temporalio/testing.rb +4 -169
- data/lib/temporalio/version.rb +3 -1
- data/lib/temporalio/worker/activity_executor/fiber.rb +49 -0
- data/lib/temporalio/worker/activity_executor/thread_pool.rb +254 -0
- data/lib/temporalio/worker/activity_executor.rb +55 -0
- data/lib/temporalio/worker/interceptor.rb +88 -0
- data/lib/temporalio/worker/tuner.rb +151 -0
- data/lib/temporalio/worker.rb +385 -163
- data/lib/temporalio/workflow_history.rb +22 -0
- data/lib/temporalio.rb +2 -7
- data/temporalio.gemspec +20 -38
- metadata +131 -596
- data/bridge/Cargo.lock +0 -2997
- data/bridge/Cargo.toml +0 -29
- data/bridge/sdk-core/ARCHITECTURE.md +0 -76
- data/bridge/sdk-core/Cargo.toml +0 -2
- data/bridge/sdk-core/LICENSE.txt +0 -23
- data/bridge/sdk-core/README.md +0 -117
- data/bridge/sdk-core/arch_docs/diagrams/README.md +0 -10
- data/bridge/sdk-core/arch_docs/diagrams/sticky_queues.puml +0 -40
- data/bridge/sdk-core/arch_docs/diagrams/workflow_internals.svg +0 -1
- data/bridge/sdk-core/arch_docs/sticky_queues.md +0 -51
- data/bridge/sdk-core/client/Cargo.toml +0 -40
- data/bridge/sdk-core/client/LICENSE.txt +0 -23
- data/bridge/sdk-core/client/src/lib.rs +0 -1462
- data/bridge/sdk-core/client/src/metrics.rs +0 -174
- data/bridge/sdk-core/client/src/raw.rs +0 -932
- data/bridge/sdk-core/client/src/retry.rs +0 -763
- data/bridge/sdk-core/client/src/workflow_handle/mod.rs +0 -185
- data/bridge/sdk-core/core/Cargo.toml +0 -129
- data/bridge/sdk-core/core/LICENSE.txt +0 -23
- data/bridge/sdk-core/core/benches/workflow_replay.rs +0 -76
- data/bridge/sdk-core/core/src/abstractions.rs +0 -355
- data/bridge/sdk-core/core/src/core_tests/activity_tasks.rs +0 -1049
- data/bridge/sdk-core/core/src/core_tests/child_workflows.rs +0 -221
- data/bridge/sdk-core/core/src/core_tests/determinism.rs +0 -270
- data/bridge/sdk-core/core/src/core_tests/local_activities.rs +0 -1046
- data/bridge/sdk-core/core/src/core_tests/mod.rs +0 -100
- data/bridge/sdk-core/core/src/core_tests/queries.rs +0 -893
- data/bridge/sdk-core/core/src/core_tests/replay_flag.rs +0 -65
- data/bridge/sdk-core/core/src/core_tests/workers.rs +0 -257
- data/bridge/sdk-core/core/src/core_tests/workflow_cancels.rs +0 -124
- data/bridge/sdk-core/core/src/core_tests/workflow_tasks.rs +0 -2433
- data/bridge/sdk-core/core/src/ephemeral_server/mod.rs +0 -609
- data/bridge/sdk-core/core/src/internal_flags.rs +0 -136
- data/bridge/sdk-core/core/src/lib.rs +0 -289
- data/bridge/sdk-core/core/src/pollers/mod.rs +0 -54
- data/bridge/sdk-core/core/src/pollers/poll_buffer.rs +0 -297
- data/bridge/sdk-core/core/src/protosext/mod.rs +0 -428
- data/bridge/sdk-core/core/src/replay/mod.rs +0 -215
- data/bridge/sdk-core/core/src/retry_logic.rs +0 -202
- data/bridge/sdk-core/core/src/telemetry/log_export.rs +0 -190
- data/bridge/sdk-core/core/src/telemetry/metrics.rs +0 -462
- data/bridge/sdk-core/core/src/telemetry/mod.rs +0 -423
- data/bridge/sdk-core/core/src/telemetry/prometheus_server.rs +0 -83
- data/bridge/sdk-core/core/src/test_help/mod.rs +0 -939
- data/bridge/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +0 -536
- data/bridge/sdk-core/core/src/worker/activities/activity_task_poller_stream.rs +0 -89
- data/bridge/sdk-core/core/src/worker/activities/local_activities.rs +0 -1278
- data/bridge/sdk-core/core/src/worker/activities.rs +0 -557
- data/bridge/sdk-core/core/src/worker/client/mocks.rs +0 -107
- data/bridge/sdk-core/core/src/worker/client.rs +0 -389
- data/bridge/sdk-core/core/src/worker/mod.rs +0 -677
- data/bridge/sdk-core/core/src/worker/workflow/bridge.rs +0 -35
- data/bridge/sdk-core/core/src/worker/workflow/driven_workflow.rs +0 -99
- data/bridge/sdk-core/core/src/worker/workflow/history_update.rs +0 -1111
- data/bridge/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +0 -964
- data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +0 -294
- data/bridge/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +0 -168
- data/bridge/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +0 -918
- data/bridge/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +0 -137
- data/bridge/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +0 -158
- data/bridge/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +0 -130
- data/bridge/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +0 -1525
- data/bridge/sdk-core/core/src/worker/workflow/machines/mod.rs +0 -324
- data/bridge/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +0 -179
- data/bridge/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +0 -659
- data/bridge/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +0 -439
- data/bridge/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +0 -435
- data/bridge/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +0 -175
- data/bridge/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +0 -249
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +0 -85
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +0 -1280
- data/bridge/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +0 -269
- data/bridge/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +0 -213
- data/bridge/sdk-core/core/src/worker/workflow/managed_run.rs +0 -1305
- data/bridge/sdk-core/core/src/worker/workflow/mod.rs +0 -1276
- data/bridge/sdk-core/core/src/worker/workflow/run_cache.rs +0 -128
- data/bridge/sdk-core/core/src/worker/workflow/wft_extraction.rs +0 -125
- data/bridge/sdk-core/core/src/worker/workflow/wft_poller.rs +0 -85
- data/bridge/sdk-core/core/src/worker/workflow/workflow_stream/saved_wf_inputs.rs +0 -117
- data/bridge/sdk-core/core/src/worker/workflow/workflow_stream/tonic_status_serde.rs +0 -24
- data/bridge/sdk-core/core/src/worker/workflow/workflow_stream.rs +0 -715
- data/bridge/sdk-core/core-api/Cargo.toml +0 -33
- data/bridge/sdk-core/core-api/LICENSE.txt +0 -23
- data/bridge/sdk-core/core-api/src/errors.rs +0 -62
- data/bridge/sdk-core/core-api/src/lib.rs +0 -113
- data/bridge/sdk-core/core-api/src/telemetry.rs +0 -141
- data/bridge/sdk-core/core-api/src/worker.rs +0 -161
- data/bridge/sdk-core/etc/deps.svg +0 -162
- data/bridge/sdk-core/etc/dynamic-config.yaml +0 -2
- data/bridge/sdk-core/etc/otel-collector-config.yaml +0 -36
- data/bridge/sdk-core/etc/prometheus.yaml +0 -6
- data/bridge/sdk-core/etc/regen-depgraph.sh +0 -5
- data/bridge/sdk-core/fsm/Cargo.toml +0 -18
- data/bridge/sdk-core/fsm/LICENSE.txt +0 -23
- data/bridge/sdk-core/fsm/README.md +0 -3
- data/bridge/sdk-core/fsm/rustfsm_procmacro/Cargo.toml +0 -27
- data/bridge/sdk-core/fsm/rustfsm_procmacro/LICENSE.txt +0 -23
- data/bridge/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +0 -650
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/progress.rs +0 -8
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/dupe_transitions_fail.rs +0 -18
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/dupe_transitions_fail.stderr +0 -12
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/dynamic_dest_pass.rs +0 -41
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/forgot_name_fail.rs +0 -14
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/forgot_name_fail.stderr +0 -11
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/handler_arg_pass.rs +0 -32
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/handler_pass.rs +0 -31
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/medium_complex_pass.rs +0 -46
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.rs +0 -29
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +0 -12
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/simple_pass.rs +0 -32
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/struct_event_variant_fail.rs +0 -18
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/struct_event_variant_fail.stderr +0 -5
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_more_item_event_variant_fail.rs +0 -11
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_more_item_event_variant_fail.stderr +0 -5
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_zero_item_event_variant_fail.rs +0 -11
- data/bridge/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/tuple_zero_item_event_variant_fail.stderr +0 -5
- data/bridge/sdk-core/fsm/rustfsm_trait/Cargo.toml +0 -14
- data/bridge/sdk-core/fsm/rustfsm_trait/LICENSE.txt +0 -23
- data/bridge/sdk-core/fsm/rustfsm_trait/src/lib.rs +0 -254
- data/bridge/sdk-core/fsm/src/lib.rs +0 -2
- data/bridge/sdk-core/histories/evict_while_la_running_no_interference-16_history.bin +0 -0
- data/bridge/sdk-core/histories/evict_while_la_running_no_interference-23_history.bin +0 -0
- data/bridge/sdk-core/histories/evict_while_la_running_no_interference-85_history.bin +0 -0
- data/bridge/sdk-core/histories/fail_wf_task.bin +0 -0
- data/bridge/sdk-core/histories/timer_workflow_history.bin +0 -0
- data/bridge/sdk-core/integ-with-otel.sh +0 -7
- data/bridge/sdk-core/protos/api_upstream/README.md +0 -9
- data/bridge/sdk-core/protos/api_upstream/api-linter.yaml +0 -40
- data/bridge/sdk-core/protos/api_upstream/buf.yaml +0 -9
- data/bridge/sdk-core/protos/api_upstream/build/go.mod +0 -7
- data/bridge/sdk-core/protos/api_upstream/build/go.sum +0 -5
- data/bridge/sdk-core/protos/api_upstream/build/tools.go +0 -29
- data/bridge/sdk-core/protos/api_upstream/dependencies/gogoproto/gogo.proto +0 -141
- data/bridge/sdk-core/protos/api_upstream/go.mod +0 -6
- data/bridge/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +0 -89
- data/bridge/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +0 -248
- data/bridge/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +0 -123
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +0 -47
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +0 -52
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +0 -56
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +0 -170
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +0 -123
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +0 -51
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +0 -50
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +0 -41
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +0 -60
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +0 -59
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +0 -56
- data/bridge/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +0 -122
- data/bridge/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +0 -108
- data/bridge/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +0 -114
- data/bridge/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +0 -56
- data/bridge/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +0 -787
- data/bridge/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +0 -99
- data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +0 -124
- data/bridge/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +0 -80
- data/bridge/sdk-core/protos/api_upstream/temporal/api/protocol/v1/message.proto +0 -57
- data/bridge/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +0 -61
- data/bridge/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +0 -55
- data/bridge/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +0 -379
- data/bridge/sdk-core/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +0 -63
- data/bridge/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +0 -108
- data/bridge/sdk-core/protos/api_upstream/temporal/api/update/v1/message.proto +0 -111
- data/bridge/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +0 -59
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +0 -146
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +0 -1199
- data/bridge/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +0 -415
- data/bridge/sdk-core/protos/grpc/health/v1/health.proto +0 -63
- data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +0 -79
- data/bridge/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +0 -80
- data/bridge/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +0 -78
- data/bridge/sdk-core/protos/local/temporal/sdk/core/common/common.proto +0 -16
- data/bridge/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +0 -31
- data/bridge/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +0 -31
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +0 -270
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +0 -305
- data/bridge/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +0 -35
- data/bridge/sdk-core/protos/testsrv_upstream/api-linter.yaml +0 -38
- data/bridge/sdk-core/protos/testsrv_upstream/buf.yaml +0 -13
- data/bridge/sdk-core/protos/testsrv_upstream/dependencies/gogoproto/gogo.proto +0 -141
- data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +0 -63
- data/bridge/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +0 -90
- data/bridge/sdk-core/rustfmt.toml +0 -1
- data/bridge/sdk-core/sdk/Cargo.toml +0 -48
- data/bridge/sdk-core/sdk/LICENSE.txt +0 -23
- data/bridge/sdk-core/sdk/src/activity_context.rs +0 -230
- data/bridge/sdk-core/sdk/src/app_data.rs +0 -37
- data/bridge/sdk-core/sdk/src/interceptors.rs +0 -50
- data/bridge/sdk-core/sdk/src/lib.rs +0 -861
- data/bridge/sdk-core/sdk/src/payload_converter.rs +0 -11
- data/bridge/sdk-core/sdk/src/workflow_context/options.rs +0 -295
- data/bridge/sdk-core/sdk/src/workflow_context.rs +0 -694
- data/bridge/sdk-core/sdk/src/workflow_future.rs +0 -500
- data/bridge/sdk-core/sdk-core-protos/Cargo.toml +0 -33
- data/bridge/sdk-core/sdk-core-protos/LICENSE.txt +0 -23
- data/bridge/sdk-core/sdk-core-protos/build.rs +0 -142
- data/bridge/sdk-core/sdk-core-protos/src/constants.rs +0 -7
- data/bridge/sdk-core/sdk-core-protos/src/history_builder.rs +0 -557
- data/bridge/sdk-core/sdk-core-protos/src/history_info.rs +0 -234
- data/bridge/sdk-core/sdk-core-protos/src/lib.rs +0 -2088
- data/bridge/sdk-core/sdk-core-protos/src/task_token.rs +0 -48
- data/bridge/sdk-core/sdk-core-protos/src/utilities.rs +0 -14
- data/bridge/sdk-core/test-utils/Cargo.toml +0 -38
- data/bridge/sdk-core/test-utils/src/canned_histories.rs +0 -1389
- data/bridge/sdk-core/test-utils/src/histfetch.rs +0 -28
- data/bridge/sdk-core/test-utils/src/lib.rs +0 -709
- data/bridge/sdk-core/test-utils/src/wf_input_saver.rs +0 -50
- data/bridge/sdk-core/test-utils/src/workflows.rs +0 -29
- data/bridge/sdk-core/tests/fuzzy_workflow.rs +0 -130
- data/bridge/sdk-core/tests/heavy_tests.rs +0 -265
- data/bridge/sdk-core/tests/integ_tests/client_tests.rs +0 -36
- data/bridge/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +0 -150
- data/bridge/sdk-core/tests/integ_tests/heartbeat_tests.rs +0 -223
- data/bridge/sdk-core/tests/integ_tests/metrics_tests.rs +0 -239
- data/bridge/sdk-core/tests/integ_tests/polling_tests.rs +0 -90
- data/bridge/sdk-core/tests/integ_tests/queries_tests.rs +0 -314
- data/bridge/sdk-core/tests/integ_tests/visibility_tests.rs +0 -151
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/activities.rs +0 -902
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/appdata_propagation.rs +0 -61
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +0 -60
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +0 -51
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +0 -51
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +0 -64
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +0 -47
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +0 -669
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +0 -54
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/patches.rs +0 -92
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/replay.rs +0 -228
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/resets.rs +0 -94
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/signals.rs +0 -171
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +0 -85
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/timers.rs +0 -120
- data/bridge/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +0 -77
- data/bridge/sdk-core/tests/integ_tests/workflow_tests.rs +0 -596
- data/bridge/sdk-core/tests/main.rs +0 -103
- data/bridge/sdk-core/tests/runner.rs +0 -132
- data/bridge/sdk-core/tests/wf_input_replay.rs +0 -32
- data/bridge/src/connection.rs +0 -202
- data/bridge/src/lib.rs +0 -494
- data/bridge/src/runtime.rs +0 -54
- data/bridge/src/test_server.rs +0 -153
- data/bridge/src/worker.rs +0 -197
- data/ext/Rakefile +0 -9
- data/lib/gen/dependencies/gogoproto/gogo_pb.rb +0 -14
- data/lib/gen/temporal/api/batch/v1/message_pb.rb +0 -50
- data/lib/gen/temporal/api/command/v1/message_pb.rb +0 -160
- data/lib/gen/temporal/api/common/v1/message_pb.rb +0 -73
- data/lib/gen/temporal/api/enums/v1/batch_operation_pb.rb +0 -33
- data/lib/gen/temporal/api/enums/v1/command_type_pb.rb +0 -37
- data/lib/gen/temporal/api/enums/v1/common_pb.rb +0 -42
- data/lib/gen/temporal/api/enums/v1/event_type_pb.rb +0 -68
- data/lib/gen/temporal/api/enums/v1/failed_cause_pb.rb +0 -79
- data/lib/gen/temporal/api/enums/v1/namespace_pb.rb +0 -37
- data/lib/gen/temporal/api/enums/v1/query_pb.rb +0 -31
- data/lib/gen/temporal/api/enums/v1/reset_pb.rb +0 -24
- data/lib/gen/temporal/api/enums/v1/schedule_pb.rb +0 -28
- data/lib/gen/temporal/api/enums/v1/task_queue_pb.rb +0 -30
- data/lib/gen/temporal/api/enums/v1/update_pb.rb +0 -25
- data/lib/gen/temporal/api/enums/v1/workflow_pb.rb +0 -89
- data/lib/gen/temporal/api/errordetails/v1/message_pb.rb +0 -84
- data/lib/gen/temporal/api/failure/v1/message_pb.rb +0 -83
- data/lib/gen/temporal/api/filter/v1/message_pb.rb +0 -40
- data/lib/gen/temporal/api/history/v1/message_pb.rb +0 -498
- data/lib/gen/temporal/api/namespace/v1/message_pb.rb +0 -64
- data/lib/gen/temporal/api/operatorservice/v1/request_response_pb.rb +0 -88
- data/lib/gen/temporal/api/operatorservice/v1/service_pb.rb +0 -20
- data/lib/gen/temporal/api/protocol/v1/message_pb.rb +0 -30
- data/lib/gen/temporal/api/query/v1/message_pb.rb +0 -38
- data/lib/gen/temporal/api/replication/v1/message_pb.rb +0 -37
- data/lib/gen/temporal/api/schedule/v1/message_pb.rb +0 -149
- data/lib/gen/temporal/api/sdk/v1/task_complete_metadata_pb.rb +0 -23
- data/lib/gen/temporal/api/taskqueue/v1/message_pb.rb +0 -73
- data/lib/gen/temporal/api/testservice/v1/request_response_pb.rb +0 -49
- data/lib/gen/temporal/api/testservice/v1/service_pb.rb +0 -21
- data/lib/gen/temporal/api/update/v1/message_pb.rb +0 -72
- data/lib/gen/temporal/api/version/v1/message_pb.rb +0 -41
- data/lib/gen/temporal/api/workflow/v1/message_pb.rb +0 -111
- data/lib/gen/temporal/api/workflowservice/v1/request_response_pb.rb +0 -798
- data/lib/gen/temporal/api/workflowservice/v1/service_pb.rb +0 -20
- data/lib/gen/temporal/sdk/core/activity_result/activity_result_pb.rb +0 -62
- data/lib/gen/temporal/sdk/core/activity_task/activity_task_pb.rb +0 -61
- data/lib/gen/temporal/sdk/core/child_workflow/child_workflow_pb.rb +0 -61
- data/lib/gen/temporal/sdk/core/common/common_pb.rb +0 -26
- data/lib/gen/temporal/sdk/core/core_interface_pb.rb +0 -40
- data/lib/gen/temporal/sdk/core/external_data/external_data_pb.rb +0 -31
- data/lib/gen/temporal/sdk/core/workflow_activation/workflow_activation_pb.rb +0 -171
- data/lib/gen/temporal/sdk/core/workflow_commands/workflow_commands_pb.rb +0 -200
- data/lib/gen/temporal/sdk/core/workflow_completion/workflow_completion_pb.rb +0 -41
- data/lib/temporalio/bridge/connect_options.rb +0 -15
- data/lib/temporalio/bridge/error.rb +0 -8
- data/lib/temporalio/bridge/retry_config.rb +0 -24
- data/lib/temporalio/bridge/tls_options.rb +0 -19
- data/lib/temporalio/bridge.rb +0 -14
- data/lib/temporalio/client/implementation.rb +0 -340
- data/lib/temporalio/connection/retry_config.rb +0 -44
- data/lib/temporalio/connection/service.rb +0 -20
- data/lib/temporalio/connection/test_service.rb +0 -92
- data/lib/temporalio/connection/tls_options.rb +0 -51
- data/lib/temporalio/connection/workflow_service.rb +0 -731
- data/lib/temporalio/connection.rb +0 -86
- data/lib/temporalio/data_converter.rb +0 -191
- data/lib/temporalio/error/workflow_failure.rb +0 -19
- data/lib/temporalio/errors.rb +0 -40
- data/lib/temporalio/failure_converter/base.rb +0 -26
- data/lib/temporalio/failure_converter/basic.rb +0 -319
- data/lib/temporalio/failure_converter.rb +0 -7
- data/lib/temporalio/interceptor/activity_inbound.rb +0 -22
- data/lib/temporalio/interceptor/activity_outbound.rb +0 -24
- data/lib/temporalio/interceptor/chain.rb +0 -28
- data/lib/temporalio/interceptor/client.rb +0 -127
- data/lib/temporalio/interceptor.rb +0 -22
- data/lib/temporalio/payload_codec/base.rb +0 -32
- data/lib/temporalio/payload_converter/base.rb +0 -24
- data/lib/temporalio/payload_converter/bytes.rb +0 -27
- data/lib/temporalio/payload_converter/composite.rb +0 -49
- data/lib/temporalio/payload_converter/encoding_base.rb +0 -35
- data/lib/temporalio/payload_converter/json.rb +0 -26
- data/lib/temporalio/payload_converter/nil.rb +0 -26
- data/lib/temporalio/payload_converter.rb +0 -14
- data/lib/temporalio/retry_state.rb +0 -35
- data/lib/temporalio/testing/time_skipping_handle.rb +0 -32
- data/lib/temporalio/testing/time_skipping_interceptor.rb +0 -23
- data/lib/temporalio/timeout_type.rb +0 -29
- data/lib/temporalio/worker/activity_runner.rb +0 -114
- data/lib/temporalio/worker/activity_worker.rb +0 -164
- data/lib/temporalio/worker/reactor.rb +0 -46
- data/lib/temporalio/worker/runner.rb +0 -63
- data/lib/temporalio/worker/sync_worker.rb +0 -124
- data/lib/temporalio/worker/thread_pool_executor.rb +0 -51
- data/lib/temporalio/workflow/async.rb +0 -46
- data/lib/temporalio/workflow/execution_info.rb +0 -54
- data/lib/temporalio/workflow/execution_status.rb +0 -36
- data/lib/temporalio/workflow/future.rb +0 -138
- data/lib/temporalio/workflow/id_reuse_policy.rb +0 -36
- data/lib/temporalio/workflow/info.rb +0 -76
- data/lib/temporalio/workflow/query_reject_condition.rb +0 -33
- data/lib/thermite_patch.rb +0 -23
@@ -1,939 +0,0 @@
|
|
1
|
-
pub(crate) use temporal_sdk_core_test_utils::canned_histories;
|
2
|
-
|
3
|
-
use crate::{
|
4
|
-
pollers::{BoxedActPoller, BoxedPoller, BoxedWFPoller, MockManualPoller, MockPoller},
|
5
|
-
protosext::ValidPollWFTQResponse,
|
6
|
-
replay::TestHistoryBuilder,
|
7
|
-
sticky_q_name_for_worker,
|
8
|
-
telemetry::metrics::MetricsContext,
|
9
|
-
worker::{
|
10
|
-
client::{
|
11
|
-
mocks::mock_workflow_client, MockWorkerClient, WorkerClient, WorkflowTaskCompletion,
|
12
|
-
},
|
13
|
-
new_wft_poller,
|
14
|
-
},
|
15
|
-
TaskToken, Worker, WorkerConfig, WorkerConfigBuilder,
|
16
|
-
};
|
17
|
-
use async_trait::async_trait;
|
18
|
-
use bimap::BiMap;
|
19
|
-
use futures::{future::BoxFuture, stream, stream::BoxStream, FutureExt, Stream, StreamExt};
|
20
|
-
use mockall::TimesRange;
|
21
|
-
use parking_lot::RwLock;
|
22
|
-
use std::{
|
23
|
-
collections::{BTreeMap, HashMap, HashSet, VecDeque},
|
24
|
-
ops::{Deref, DerefMut},
|
25
|
-
pin::Pin,
|
26
|
-
sync::{
|
27
|
-
atomic::{AtomicBool, Ordering},
|
28
|
-
Arc,
|
29
|
-
},
|
30
|
-
task::{Context, Poll},
|
31
|
-
time::Duration,
|
32
|
-
};
|
33
|
-
use temporal_sdk_core_api::errors::{PollActivityError, PollWfError};
|
34
|
-
use temporal_sdk_core_api::Worker as WorkerTrait;
|
35
|
-
use temporal_sdk_core_protos::{
|
36
|
-
coresdk::{
|
37
|
-
workflow_activation::WorkflowActivation,
|
38
|
-
workflow_commands::workflow_command,
|
39
|
-
workflow_completion::{self, workflow_activation_completion, WorkflowActivationCompletion},
|
40
|
-
},
|
41
|
-
temporal::api::{
|
42
|
-
common::v1::WorkflowExecution,
|
43
|
-
enums::v1::WorkflowTaskFailedCause,
|
44
|
-
failure::v1::Failure,
|
45
|
-
workflowservice::v1::{
|
46
|
-
PollActivityTaskQueueResponse, PollWorkflowTaskQueueResponse,
|
47
|
-
RespondWorkflowTaskCompletedResponse,
|
48
|
-
},
|
49
|
-
},
|
50
|
-
};
|
51
|
-
use temporal_sdk_core_test_utils::TestWorker;
|
52
|
-
use tokio::sync::{mpsc::unbounded_channel, Notify};
|
53
|
-
use tokio_stream::wrappers::UnboundedReceiverStream;
|
54
|
-
use tokio_util::sync::CancellationToken;
|
55
|
-
|
56
|
-
pub const TEST_Q: &str = "q";
|
57
|
-
|
58
|
-
pub fn test_worker_cfg() -> WorkerConfigBuilder {
|
59
|
-
let mut wcb = WorkerConfigBuilder::default();
|
60
|
-
wcb.namespace("default")
|
61
|
-
.task_queue(TEST_Q)
|
62
|
-
.worker_build_id("test_bin_id")
|
63
|
-
.ignore_evicts_on_shutdown(true)
|
64
|
-
// Serial polling since it makes mocking much easier.
|
65
|
-
.max_concurrent_wft_polls(1_usize);
|
66
|
-
wcb
|
67
|
-
}
|
68
|
-
|
69
|
-
/// When constructing responses for mocks, indicates how a given response should be built
|
70
|
-
#[derive(derive_more::From)]
|
71
|
-
#[allow(clippy::large_enum_variant)] // Test only code, whatever.
|
72
|
-
pub enum ResponseType {
|
73
|
-
ToTaskNum(usize),
|
74
|
-
/// Returns just the history after the WFT completed of the provided task number - 1, through to
|
75
|
-
/// the next WFT started. Simulating the incremental history for just the provided task number
|
76
|
-
#[from(ignore)]
|
77
|
-
OneTask(usize),
|
78
|
-
/// Waits until the future resolves before responding as `ToTaskNum` with the provided number
|
79
|
-
UntilResolved(BoxFuture<'static, ()>, usize),
|
80
|
-
/// Waits until the future resolves before responding with the provided response
|
81
|
-
UntilResolvedRaw(BoxFuture<'static, ()>, PollWorkflowTaskQueueResponse),
|
82
|
-
AllHistory,
|
83
|
-
Raw(PollWorkflowTaskQueueResponse),
|
84
|
-
}
|
85
|
-
#[derive(Eq, PartialEq, Hash)]
|
86
|
-
pub enum HashableResponseType {
|
87
|
-
ToTaskNum(usize),
|
88
|
-
OneTask(usize),
|
89
|
-
UntilResolved(usize),
|
90
|
-
UntilResolvedRaw(TaskToken),
|
91
|
-
AllHistory,
|
92
|
-
Raw(TaskToken),
|
93
|
-
}
|
94
|
-
impl ResponseType {
|
95
|
-
pub fn hashable(&self) -> HashableResponseType {
|
96
|
-
match self {
|
97
|
-
ResponseType::ToTaskNum(x) => HashableResponseType::ToTaskNum(*x),
|
98
|
-
ResponseType::OneTask(x) => HashableResponseType::OneTask(*x),
|
99
|
-
ResponseType::AllHistory => HashableResponseType::AllHistory,
|
100
|
-
ResponseType::Raw(r) => HashableResponseType::Raw(r.task_token.clone().into()),
|
101
|
-
ResponseType::UntilResolved(_, x) => HashableResponseType::UntilResolved(*x),
|
102
|
-
ResponseType::UntilResolvedRaw(_, r) => {
|
103
|
-
HashableResponseType::UntilResolvedRaw(r.task_token.clone().into())
|
104
|
-
}
|
105
|
-
}
|
106
|
-
}
|
107
|
-
}
|
108
|
-
impl From<&usize> for ResponseType {
|
109
|
-
fn from(u: &usize) -> Self {
|
110
|
-
Self::ToTaskNum(*u)
|
111
|
-
}
|
112
|
-
}
|
113
|
-
|
114
|
-
/// Given identifiers for a workflow/run, and a test history builder, construct an instance of
|
115
|
-
/// the a worker with a mock server client that will produce the responses as appropriate.
|
116
|
-
///
|
117
|
-
/// `response_batches` is used to control the fake [PollWorkflowTaskQueueResponse]s returned. For
|
118
|
-
/// each number in the input list, a fake response will be prepared which includes history up to the
|
119
|
-
/// workflow task with that number, as in [TestHistoryBuilder::get_history_info].
|
120
|
-
pub(crate) fn build_fake_worker(
|
121
|
-
wf_id: &str,
|
122
|
-
t: TestHistoryBuilder,
|
123
|
-
response_batches: impl IntoIterator<Item = impl Into<ResponseType>>,
|
124
|
-
) -> Worker {
|
125
|
-
let response_batches = response_batches.into_iter().map(Into::into).collect();
|
126
|
-
let mock_holder = build_multihist_mock_sg(
|
127
|
-
vec![FakeWfResponses {
|
128
|
-
wf_id: wf_id.to_owned(),
|
129
|
-
hist: t,
|
130
|
-
response_batches,
|
131
|
-
}],
|
132
|
-
true,
|
133
|
-
0,
|
134
|
-
);
|
135
|
-
mock_worker(mock_holder)
|
136
|
-
}
|
137
|
-
|
138
|
-
pub(crate) fn mock_worker(mocks: MocksHolder) -> Worker {
|
139
|
-
let sticky_q = sticky_q_name_for_worker("unit-test", &mocks.inputs.config);
|
140
|
-
let act_poller = if mocks.inputs.config.no_remote_activities {
|
141
|
-
None
|
142
|
-
} else {
|
143
|
-
mocks.inputs.act_poller
|
144
|
-
};
|
145
|
-
Worker::new_with_pollers(
|
146
|
-
mocks.inputs.config,
|
147
|
-
sticky_q,
|
148
|
-
mocks.client,
|
149
|
-
mocks.inputs.wft_stream,
|
150
|
-
act_poller,
|
151
|
-
MetricsContext::no_op(),
|
152
|
-
None,
|
153
|
-
CancellationToken::new(),
|
154
|
-
)
|
155
|
-
}
|
156
|
-
|
157
|
-
pub(crate) fn mock_sdk(poll_cfg: MockPollCfg) -> TestWorker {
|
158
|
-
mock_sdk_cfg(poll_cfg, |_| {})
|
159
|
-
}
|
160
|
-
pub(crate) fn mock_sdk_cfg(
|
161
|
-
mut poll_cfg: MockPollCfg,
|
162
|
-
mutator: impl FnOnce(&mut WorkerConfig),
|
163
|
-
) -> TestWorker {
|
164
|
-
poll_cfg.using_rust_sdk = true;
|
165
|
-
let mut mock = build_mock_pollers(poll_cfg);
|
166
|
-
mock.worker_cfg(mutator);
|
167
|
-
let core = mock_worker(mock);
|
168
|
-
TestWorker::new(Arc::new(core), TEST_Q.to_string())
|
169
|
-
}
|
170
|
-
|
171
|
-
pub struct FakeWfResponses {
|
172
|
-
pub wf_id: String,
|
173
|
-
pub hist: TestHistoryBuilder,
|
174
|
-
pub response_batches: Vec<ResponseType>,
|
175
|
-
}
|
176
|
-
|
177
|
-
// TODO: Should be all-internal to this module
|
178
|
-
pub struct MocksHolder {
|
179
|
-
client: Arc<dyn WorkerClient>,
|
180
|
-
inputs: MockWorkerInputs,
|
181
|
-
pub outstanding_task_map: Option<OutstandingWFTMap>,
|
182
|
-
}
|
183
|
-
|
184
|
-
impl MocksHolder {
|
185
|
-
pub fn worker_cfg(&mut self, mutator: impl FnOnce(&mut WorkerConfig)) {
|
186
|
-
mutator(&mut self.inputs.config);
|
187
|
-
}
|
188
|
-
pub fn set_act_poller(&mut self, poller: BoxedActPoller) {
|
189
|
-
self.inputs.act_poller = Some(poller);
|
190
|
-
}
|
191
|
-
/// Can be used for tests that need to avoid auto-shutdown due to running out of mock responses
|
192
|
-
pub fn make_wft_stream_interminable(&mut self) {
|
193
|
-
let old_stream = std::mem::replace(&mut self.inputs.wft_stream, stream::pending().boxed());
|
194
|
-
self.inputs.wft_stream = old_stream.chain(stream::pending()).boxed();
|
195
|
-
}
|
196
|
-
}
|
197
|
-
|
198
|
-
pub struct MockWorkerInputs {
|
199
|
-
pub wft_stream: BoxStream<'static, Result<ValidPollWFTQResponse, tonic::Status>>,
|
200
|
-
pub act_poller: Option<BoxedActPoller>,
|
201
|
-
pub config: WorkerConfig,
|
202
|
-
}
|
203
|
-
|
204
|
-
impl Default for MockWorkerInputs {
|
205
|
-
fn default() -> Self {
|
206
|
-
Self::new_from_poller(Box::from(mock_poller()))
|
207
|
-
}
|
208
|
-
}
|
209
|
-
|
210
|
-
impl MockWorkerInputs {
|
211
|
-
pub fn new(
|
212
|
-
wft_stream: BoxStream<'static, Result<ValidPollWFTQResponse, tonic::Status>>,
|
213
|
-
) -> Self {
|
214
|
-
Self {
|
215
|
-
wft_stream,
|
216
|
-
act_poller: None,
|
217
|
-
config: test_worker_cfg().build().unwrap(),
|
218
|
-
}
|
219
|
-
}
|
220
|
-
pub fn new_from_poller(wf_poller: BoxedWFPoller) -> Self {
|
221
|
-
Self {
|
222
|
-
wft_stream: new_wft_poller(wf_poller, MetricsContext::no_op()).boxed(),
|
223
|
-
act_poller: None,
|
224
|
-
config: test_worker_cfg().build().unwrap(),
|
225
|
-
}
|
226
|
-
}
|
227
|
-
}
|
228
|
-
|
229
|
-
impl MocksHolder {
|
230
|
-
pub(crate) fn from_mock_worker(
|
231
|
-
client: impl WorkerClient + 'static,
|
232
|
-
mock_worker: MockWorkerInputs,
|
233
|
-
) -> Self {
|
234
|
-
Self {
|
235
|
-
client: Arc::new(client),
|
236
|
-
inputs: mock_worker,
|
237
|
-
outstanding_task_map: None,
|
238
|
-
}
|
239
|
-
}
|
240
|
-
|
241
|
-
/// Uses the provided list of tasks to create a mock poller for the `TEST_Q`
|
242
|
-
pub(crate) fn from_client_with_activities<ACT>(
|
243
|
-
client: impl WorkerClient + 'static,
|
244
|
-
act_tasks: ACT,
|
245
|
-
) -> Self
|
246
|
-
where
|
247
|
-
ACT: IntoIterator<Item = QueueResponse<PollActivityTaskQueueResponse>>,
|
248
|
-
<ACT as IntoIterator>::IntoIter: Send + 'static,
|
249
|
-
{
|
250
|
-
let wft_stream = stream::pending().boxed();
|
251
|
-
let mock_act_poller = mock_poller_from_resps(act_tasks);
|
252
|
-
let mock_worker = MockWorkerInputs {
|
253
|
-
wft_stream,
|
254
|
-
act_poller: Some(mock_act_poller),
|
255
|
-
config: test_worker_cfg().build().unwrap(),
|
256
|
-
};
|
257
|
-
Self {
|
258
|
-
client: Arc::new(client),
|
259
|
-
inputs: mock_worker,
|
260
|
-
outstanding_task_map: None,
|
261
|
-
}
|
262
|
-
}
|
263
|
-
|
264
|
-
/// Uses the provided task responses and delivers them as quickly as possible when polled.
|
265
|
-
/// This is only useful to test buffering, as typically you do not want to pretend that
|
266
|
-
/// the server is delivering WFTs super fast for the same run.
|
267
|
-
pub(crate) fn from_wft_stream(
|
268
|
-
client: impl WorkerClient + 'static,
|
269
|
-
stream: impl Stream<Item = PollWorkflowTaskQueueResponse> + Send + 'static,
|
270
|
-
) -> Self {
|
271
|
-
let wft_stream = stream
|
272
|
-
.map(|r| Ok(r.try_into().expect("Mock responses must be valid work")))
|
273
|
-
.boxed();
|
274
|
-
let mock_worker = MockWorkerInputs {
|
275
|
-
wft_stream,
|
276
|
-
act_poller: None,
|
277
|
-
config: test_worker_cfg().build().unwrap(),
|
278
|
-
};
|
279
|
-
Self {
|
280
|
-
client: Arc::new(client),
|
281
|
-
inputs: mock_worker,
|
282
|
-
outstanding_task_map: None,
|
283
|
-
}
|
284
|
-
}
|
285
|
-
}
|
286
|
-
|
287
|
-
// TODO: Un-pub ideally
|
288
|
-
pub(crate) fn mock_poller_from_resps<T, I>(tasks: I) -> BoxedPoller<T>
|
289
|
-
where
|
290
|
-
T: Send + Sync + 'static,
|
291
|
-
I: IntoIterator<Item = QueueResponse<T>>,
|
292
|
-
<I as IntoIterator>::IntoIter: Send + 'static,
|
293
|
-
{
|
294
|
-
let mut mock_poller = mock_manual_poller();
|
295
|
-
let mut tasks = tasks.into_iter();
|
296
|
-
mock_poller.expect_poll().returning(move || {
|
297
|
-
if let Some(t) = tasks.next() {
|
298
|
-
async move {
|
299
|
-
if let Some(f) = t.delay_until {
|
300
|
-
f.await;
|
301
|
-
}
|
302
|
-
Some(Ok(t.resp))
|
303
|
-
}
|
304
|
-
.boxed()
|
305
|
-
} else {
|
306
|
-
async { None }.boxed()
|
307
|
-
}
|
308
|
-
});
|
309
|
-
Box::new(mock_poller) as BoxedPoller<T>
|
310
|
-
}
|
311
|
-
|
312
|
-
pub fn mock_poller<T>() -> MockPoller<T>
|
313
|
-
where
|
314
|
-
T: Send + Sync + 'static,
|
315
|
-
{
|
316
|
-
let mut mock_poller = MockPoller::new();
|
317
|
-
mock_poller.expect_shutdown_box().return_const(());
|
318
|
-
mock_poller.expect_notify_shutdown().return_const(());
|
319
|
-
mock_poller
|
320
|
-
}
|
321
|
-
|
322
|
-
pub fn mock_manual_poller<T>() -> MockManualPoller<T>
|
323
|
-
where
|
324
|
-
T: Send + Sync + 'static,
|
325
|
-
{
|
326
|
-
let mut mock_poller = MockManualPoller::new();
|
327
|
-
mock_poller
|
328
|
-
.expect_shutdown_box()
|
329
|
-
.returning(|| async {}.boxed());
|
330
|
-
mock_poller.expect_notify_shutdown().return_const(());
|
331
|
-
mock_poller
|
332
|
-
}
|
333
|
-
|
334
|
-
/// Build a mock server client capable of returning multiple different histories for different
|
335
|
-
/// workflows. It does so by tracking outstanding workflow tasks like is also happening in core
|
336
|
-
/// (which is unfortunately a bit redundant, we could provide hooks in core but that feels a little
|
337
|
-
/// nasty). If there is an outstanding task for a given workflow, new chunks of its history are not
|
338
|
-
/// returned. If there is not, the next batch of history is returned for any workflow without an
|
339
|
-
/// outstanding task. Outstanding tasks are cleared on completion, failure, or eviction.
|
340
|
-
///
|
341
|
-
/// `num_expected_fails` can be provided to set a specific number of expected failed workflow tasks
|
342
|
-
/// sent to the server.
|
343
|
-
pub(crate) fn build_multihist_mock_sg(
|
344
|
-
hists: impl IntoIterator<Item = FakeWfResponses>,
|
345
|
-
enforce_correct_number_of_polls: bool,
|
346
|
-
num_expected_fails: usize,
|
347
|
-
) -> MocksHolder {
|
348
|
-
let mh = MockPollCfg::new(
|
349
|
-
hists.into_iter().collect(),
|
350
|
-
enforce_correct_number_of_polls,
|
351
|
-
num_expected_fails,
|
352
|
-
);
|
353
|
-
build_mock_pollers(mh)
|
354
|
-
}
|
355
|
-
|
356
|
-
/// See [build_multihist_mock_sg] -- one history convenience version
|
357
|
-
pub(crate) fn single_hist_mock_sg(
|
358
|
-
wf_id: &str,
|
359
|
-
t: TestHistoryBuilder,
|
360
|
-
response_batches: impl IntoIterator<Item = impl Into<ResponseType>>,
|
361
|
-
mock_client: MockWorkerClient,
|
362
|
-
enforce_num_polls: bool,
|
363
|
-
) -> MocksHolder {
|
364
|
-
let mut mh = MockPollCfg::from_resp_batches(wf_id, t, response_batches, mock_client);
|
365
|
-
mh.enforce_correct_number_of_polls = enforce_num_polls;
|
366
|
-
build_mock_pollers(mh)
|
367
|
-
}
|
368
|
-
|
369
|
-
#[allow(clippy::type_complexity)]
|
370
|
-
pub(crate) struct MockPollCfg {
|
371
|
-
pub hists: Vec<FakeWfResponses>,
|
372
|
-
pub enforce_correct_number_of_polls: bool,
|
373
|
-
pub num_expected_fails: usize,
|
374
|
-
pub num_expected_legacy_query_resps: usize,
|
375
|
-
pub mock_client: MockWorkerClient,
|
376
|
-
/// All calls to fail WFTs must match this predicate
|
377
|
-
pub expect_fail_wft_matcher:
|
378
|
-
Box<dyn Fn(&TaskToken, &WorkflowTaskFailedCause, &Option<Failure>) -> bool + Send>,
|
379
|
-
pub completion_asserts: Option<Box<dyn Fn(&WorkflowTaskCompletion) + Send>>,
|
380
|
-
pub num_expected_completions: Option<TimesRange>,
|
381
|
-
/// If being used with the Rust SDK, this is set true. It ensures pollers will not error out
|
382
|
-
/// early with no work, since we cannot know the exact number of times polling will happen.
|
383
|
-
/// Instead, they will just block forever.
|
384
|
-
pub using_rust_sdk: bool,
|
385
|
-
pub make_poll_stream_interminable: bool,
|
386
|
-
}
|
387
|
-
|
388
|
-
impl MockPollCfg {
|
389
|
-
pub fn new(
|
390
|
-
hists: Vec<FakeWfResponses>,
|
391
|
-
enforce_correct_number_of_polls: bool,
|
392
|
-
num_expected_fails: usize,
|
393
|
-
) -> Self {
|
394
|
-
Self {
|
395
|
-
hists,
|
396
|
-
enforce_correct_number_of_polls,
|
397
|
-
num_expected_fails,
|
398
|
-
num_expected_legacy_query_resps: 0,
|
399
|
-
mock_client: mock_workflow_client(),
|
400
|
-
expect_fail_wft_matcher: Box::new(|_, _, _| true),
|
401
|
-
completion_asserts: None,
|
402
|
-
num_expected_completions: None,
|
403
|
-
using_rust_sdk: false,
|
404
|
-
make_poll_stream_interminable: false,
|
405
|
-
}
|
406
|
-
}
|
407
|
-
pub fn from_resp_batches(
|
408
|
-
wf_id: &str,
|
409
|
-
t: TestHistoryBuilder,
|
410
|
-
resps: impl IntoIterator<Item = impl Into<ResponseType>>,
|
411
|
-
mock_client: MockWorkerClient,
|
412
|
-
) -> Self {
|
413
|
-
Self {
|
414
|
-
hists: vec![FakeWfResponses {
|
415
|
-
wf_id: wf_id.to_owned(),
|
416
|
-
hist: t,
|
417
|
-
response_batches: resps.into_iter().map(Into::into).collect(),
|
418
|
-
}],
|
419
|
-
enforce_correct_number_of_polls: true,
|
420
|
-
num_expected_fails: 0,
|
421
|
-
num_expected_legacy_query_resps: 0,
|
422
|
-
mock_client,
|
423
|
-
expect_fail_wft_matcher: Box::new(|_, _, _| true),
|
424
|
-
completion_asserts: None,
|
425
|
-
num_expected_completions: None,
|
426
|
-
using_rust_sdk: false,
|
427
|
-
make_poll_stream_interminable: false,
|
428
|
-
}
|
429
|
-
}
|
430
|
-
}
|
431
|
-
|
432
|
-
#[derive(Default, Clone)]
|
433
|
-
pub struct OutstandingWFTMap {
|
434
|
-
map: Arc<RwLock<BiMap<String, TaskToken>>>,
|
435
|
-
waker: Arc<Notify>,
|
436
|
-
all_work_delivered: Arc<AtomicBool>,
|
437
|
-
}
|
438
|
-
impl OutstandingWFTMap {
|
439
|
-
fn has_run(&self, run_id: &str) -> bool {
|
440
|
-
self.map.read().contains_left(run_id)
|
441
|
-
}
|
442
|
-
fn put_token(&self, run_id: String, token: TaskToken) {
|
443
|
-
self.map.write().insert(run_id, token);
|
444
|
-
}
|
445
|
-
fn release_token(&self, token: &TaskToken) {
|
446
|
-
self.map.write().remove_by_right(token);
|
447
|
-
self.waker.notify_one();
|
448
|
-
}
|
449
|
-
pub fn release_run(&self, run_id: &str) {
|
450
|
-
self.map.write().remove_by_left(run_id);
|
451
|
-
self.waker.notify_waiters();
|
452
|
-
}
|
453
|
-
pub fn all_work_delivered(&self) -> bool {
|
454
|
-
self.all_work_delivered.load(Ordering::Acquire)
|
455
|
-
}
|
456
|
-
}
|
457
|
-
|
458
|
-
struct EnsuresWorkDoneWFTStream {
|
459
|
-
inner: UnboundedReceiverStream<ValidPollWFTQResponse>,
|
460
|
-
all_work_was_completed: Arc<AtomicBool>,
|
461
|
-
}
|
462
|
-
impl Stream for EnsuresWorkDoneWFTStream {
|
463
|
-
type Item = ValidPollWFTQResponse;
|
464
|
-
|
465
|
-
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
466
|
-
self.inner.poll_next_unpin(cx)
|
467
|
-
}
|
468
|
-
}
|
469
|
-
impl Drop for EnsuresWorkDoneWFTStream {
|
470
|
-
fn drop(&mut self) {
|
471
|
-
if !self.all_work_was_completed.load(Ordering::Acquire) && !std::thread::panicking() {
|
472
|
-
panic!("Not all workflow tasks were taken from mock!");
|
473
|
-
}
|
474
|
-
}
|
475
|
-
}
|
476
|
-
|
477
|
-
/// Given an iterable of fake responses, return the mocks & associated data to work with them
|
478
|
-
pub(crate) fn build_mock_pollers(mut cfg: MockPollCfg) -> MocksHolder {
|
479
|
-
let mut task_q_resps: BTreeMap<String, VecDeque<_>> = BTreeMap::new();
|
480
|
-
let all_work_delivered = if cfg.enforce_correct_number_of_polls && !cfg.using_rust_sdk {
|
481
|
-
Arc::new(AtomicBool::new(false))
|
482
|
-
} else {
|
483
|
-
Arc::new(AtomicBool::new(true))
|
484
|
-
};
|
485
|
-
|
486
|
-
let outstanding_wf_task_tokens = OutstandingWFTMap {
|
487
|
-
map: Arc::new(Default::default()),
|
488
|
-
waker: Arc::new(Default::default()),
|
489
|
-
all_work_delivered: all_work_delivered.clone(),
|
490
|
-
};
|
491
|
-
|
492
|
-
for hist in cfg.hists {
|
493
|
-
let full_hist_info = hist.hist.get_full_history_info().unwrap();
|
494
|
-
// Ensure no response batch is trying to return more tasks than the history contains
|
495
|
-
for respt in &hist.response_batches {
|
496
|
-
if let ResponseType::ToTaskNum(rb_wf_num) = respt {
|
497
|
-
assert!(
|
498
|
-
*rb_wf_num <= full_hist_info.wf_task_count(),
|
499
|
-
"Wf task count {} is not <= total task count {}",
|
500
|
-
rb_wf_num,
|
501
|
-
full_hist_info.wf_task_count()
|
502
|
-
);
|
503
|
-
}
|
504
|
-
}
|
505
|
-
|
506
|
-
// Convert history batches into poll responses, while also tracking how many times a given
|
507
|
-
// history has been returned so we can increment the associated attempt number on the WFT.
|
508
|
-
// NOTE: This is hard to use properly with the `AfterEveryReply` testing eviction mode.
|
509
|
-
// Such usages need a history different from other eviction modes which would include
|
510
|
-
// WFT timeouts or something to simulate the task getting dropped.
|
511
|
-
let mut attempts_at_task_num = HashMap::new();
|
512
|
-
let responses: Vec<_> = hist
|
513
|
-
.response_batches
|
514
|
-
.into_iter()
|
515
|
-
.map(|response| {
|
516
|
-
let cur_attempt = attempts_at_task_num.entry(response.hashable()).or_insert(1);
|
517
|
-
let mut r = hist_to_poll_resp(&hist.hist, hist.wf_id.clone(), response);
|
518
|
-
r.attempt = *cur_attempt;
|
519
|
-
*cur_attempt += 1;
|
520
|
-
r
|
521
|
-
})
|
522
|
-
.collect();
|
523
|
-
|
524
|
-
let tasks = VecDeque::from(responses);
|
525
|
-
task_q_resps.insert(hist.wf_id, tasks);
|
526
|
-
}
|
527
|
-
|
528
|
-
// The poller will return history from any workflow runs that do not have currently
|
529
|
-
// outstanding tasks.
|
530
|
-
let outstanding = outstanding_wf_task_tokens.clone();
|
531
|
-
let outstanding_wakeup = outstanding.waker.clone();
|
532
|
-
let (wft_tx, wft_rx) = unbounded_channel();
|
533
|
-
tokio::task::spawn(async move {
|
534
|
-
loop {
|
535
|
-
let mut resp = None;
|
536
|
-
let mut resp_iter = task_q_resps.iter_mut();
|
537
|
-
for (_, tasks) in &mut resp_iter {
|
538
|
-
// Must extract run id from a workflow task associated with this workflow
|
539
|
-
// TODO: Case where run id changes for same workflow id is not handled here
|
540
|
-
if let Some(t) = tasks.get(0) {
|
541
|
-
let rid = t.workflow_execution.as_ref().unwrap().run_id.clone();
|
542
|
-
if !outstanding.has_run(&rid) {
|
543
|
-
let t = tasks.pop_front().unwrap();
|
544
|
-
outstanding.put_token(rid, TaskToken(t.task_token.clone()));
|
545
|
-
resp = Some(t);
|
546
|
-
break;
|
547
|
-
}
|
548
|
-
}
|
549
|
-
}
|
550
|
-
let no_tasks_for_anyone = resp_iter.next().is_none();
|
551
|
-
|
552
|
-
if let Some(resp) = resp {
|
553
|
-
if let Some(d) = resp.delay_until {
|
554
|
-
d.await;
|
555
|
-
}
|
556
|
-
if wft_tx
|
557
|
-
.send(
|
558
|
-
resp.resp
|
559
|
-
.try_into()
|
560
|
-
.expect("Mock responses must be valid work"),
|
561
|
-
)
|
562
|
-
.is_err()
|
563
|
-
{
|
564
|
-
dbg!("Exiting mock WFT task because rcv half of stream was dropped");
|
565
|
-
break;
|
566
|
-
}
|
567
|
-
}
|
568
|
-
|
569
|
-
// No more work to do
|
570
|
-
if task_q_resps.values().all(|q| q.is_empty()) {
|
571
|
-
outstanding
|
572
|
-
.all_work_delivered
|
573
|
-
.store(true, Ordering::Release);
|
574
|
-
break;
|
575
|
-
}
|
576
|
-
|
577
|
-
if no_tasks_for_anyone {
|
578
|
-
tokio::select! {
|
579
|
-
_ = outstanding_wakeup.notified() => {}
|
580
|
-
_ = tokio::time::sleep(Duration::from_secs(60)) => {}
|
581
|
-
};
|
582
|
-
}
|
583
|
-
}
|
584
|
-
});
|
585
|
-
let mock_worker = MockWorkerInputs::new(
|
586
|
-
EnsuresWorkDoneWFTStream {
|
587
|
-
inner: UnboundedReceiverStream::new(wft_rx),
|
588
|
-
all_work_was_completed: all_work_delivered,
|
589
|
-
}
|
590
|
-
.map(Ok)
|
591
|
-
.boxed(),
|
592
|
-
);
|
593
|
-
|
594
|
-
let outstanding = outstanding_wf_task_tokens.clone();
|
595
|
-
let expect_completes = cfg.mock_client.expect_complete_workflow_task();
|
596
|
-
if let Some(range) = cfg.num_expected_completions {
|
597
|
-
expect_completes.times(range);
|
598
|
-
} else if cfg.completion_asserts.is_some() {
|
599
|
-
expect_completes.times(1..);
|
600
|
-
}
|
601
|
-
expect_completes.returning(move |comp| {
|
602
|
-
if let Some(ass) = cfg.completion_asserts.as_ref() {
|
603
|
-
// tee hee
|
604
|
-
ass(&comp)
|
605
|
-
}
|
606
|
-
outstanding.release_token(&comp.task_token);
|
607
|
-
Ok(RespondWorkflowTaskCompletedResponse::default())
|
608
|
-
});
|
609
|
-
let outstanding = outstanding_wf_task_tokens.clone();
|
610
|
-
cfg.mock_client
|
611
|
-
.expect_fail_workflow_task()
|
612
|
-
.withf(cfg.expect_fail_wft_matcher)
|
613
|
-
.times::<TimesRange>(cfg.num_expected_fails.into())
|
614
|
-
.returning(move |tt, _, _| {
|
615
|
-
outstanding.release_token(&tt);
|
616
|
-
Ok(Default::default())
|
617
|
-
});
|
618
|
-
let outstanding = outstanding_wf_task_tokens.clone();
|
619
|
-
cfg.mock_client
|
620
|
-
.expect_respond_legacy_query()
|
621
|
-
.times::<TimesRange>(cfg.num_expected_legacy_query_resps.into())
|
622
|
-
.returning(move |tt, _| {
|
623
|
-
outstanding.release_token(&tt);
|
624
|
-
Ok(Default::default())
|
625
|
-
});
|
626
|
-
|
627
|
-
let mut mh = MocksHolder {
|
628
|
-
client: Arc::new(cfg.mock_client),
|
629
|
-
inputs: mock_worker,
|
630
|
-
outstanding_task_map: Some(outstanding_wf_task_tokens),
|
631
|
-
};
|
632
|
-
if cfg.make_poll_stream_interminable {
|
633
|
-
mh.make_wft_stream_interminable();
|
634
|
-
}
|
635
|
-
mh
|
636
|
-
}
|
637
|
-
|
638
|
-
pub struct QueueResponse<T> {
|
639
|
-
pub resp: T,
|
640
|
-
pub delay_until: Option<BoxFuture<'static, ()>>,
|
641
|
-
}
|
642
|
-
impl<T> From<T> for QueueResponse<T> {
|
643
|
-
fn from(resp: T) -> Self {
|
644
|
-
QueueResponse {
|
645
|
-
resp,
|
646
|
-
delay_until: None,
|
647
|
-
}
|
648
|
-
}
|
649
|
-
}
|
650
|
-
impl From<QueueResponse<PollWorkflowTaskQueueResponse>> for ResponseType {
|
651
|
-
fn from(qr: QueueResponse<PollWorkflowTaskQueueResponse>) -> Self {
|
652
|
-
if let Some(du) = qr.delay_until {
|
653
|
-
ResponseType::UntilResolvedRaw(du, qr.resp)
|
654
|
-
} else {
|
655
|
-
ResponseType::Raw(qr.resp)
|
656
|
-
}
|
657
|
-
}
|
658
|
-
}
|
659
|
-
impl<T> Deref for QueueResponse<T> {
|
660
|
-
type Target = T;
|
661
|
-
|
662
|
-
fn deref(&self) -> &Self::Target {
|
663
|
-
&self.resp
|
664
|
-
}
|
665
|
-
}
|
666
|
-
impl<T> DerefMut for QueueResponse<T> {
|
667
|
-
fn deref_mut(&mut self) -> &mut Self::Target {
|
668
|
-
&mut self.resp
|
669
|
-
}
|
670
|
-
}
|
671
|
-
|
672
|
-
pub fn hist_to_poll_resp(
|
673
|
-
t: &TestHistoryBuilder,
|
674
|
-
wf_id: impl Into<String>,
|
675
|
-
response_type: ResponseType,
|
676
|
-
) -> QueueResponse<PollWorkflowTaskQueueResponse> {
|
677
|
-
let run_id = t.get_orig_run_id();
|
678
|
-
let wf = WorkflowExecution {
|
679
|
-
workflow_id: wf_id.into(),
|
680
|
-
run_id: run_id.to_string(),
|
681
|
-
};
|
682
|
-
let mut delay_until = None;
|
683
|
-
let hist_info = match response_type {
|
684
|
-
ResponseType::ToTaskNum(tn) => t.get_history_info(tn).unwrap(),
|
685
|
-
ResponseType::OneTask(tn) => t.get_one_wft(tn).unwrap(),
|
686
|
-
ResponseType::AllHistory => t.get_full_history_info().unwrap(),
|
687
|
-
ResponseType::Raw(r) => {
|
688
|
-
return QueueResponse {
|
689
|
-
resp: r,
|
690
|
-
delay_until: None,
|
691
|
-
}
|
692
|
-
}
|
693
|
-
ResponseType::UntilResolved(fut, tn) => {
|
694
|
-
delay_until = Some(fut);
|
695
|
-
t.get_history_info(tn).unwrap()
|
696
|
-
}
|
697
|
-
ResponseType::UntilResolvedRaw(fut, r) => {
|
698
|
-
return QueueResponse {
|
699
|
-
resp: r,
|
700
|
-
delay_until: Some(fut),
|
701
|
-
}
|
702
|
-
}
|
703
|
-
};
|
704
|
-
let mut resp = hist_info.as_poll_wft_response();
|
705
|
-
resp.workflow_execution = Some(wf);
|
706
|
-
QueueResponse { resp, delay_until }
|
707
|
-
}
|
708
|
-
|
709
|
-
type AsserterWithReply<'a> = (
|
710
|
-
&'a dyn Fn(&WorkflowActivation),
|
711
|
-
workflow_activation_completion::Status,
|
712
|
-
);
|
713
|
-
|
714
|
-
/// Determines when workflows are kept in the cache or evicted for [poll_and_reply] type tests
|
715
|
-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
716
|
-
pub(crate) enum WorkflowCachingPolicy {
|
717
|
-
/// Workflows are evicted after each workflow task completion. Note that this is *not* after
|
718
|
-
/// each workflow activation - there are often multiple activations per workflow task.
|
719
|
-
NonSticky,
|
720
|
-
|
721
|
-
/// Not a real mode, but good for imitating crashes. Evict workflows after *every* reply,
|
722
|
-
/// even if there are pending activations
|
723
|
-
#[cfg(test)]
|
724
|
-
AfterEveryReply,
|
725
|
-
}
|
726
|
-
|
727
|
-
/// This function accepts a list of asserts and replies to workflow activations to run against the
|
728
|
-
/// provided instance of fake core.
|
729
|
-
///
|
730
|
-
/// It handles the business of re-sending the same activation replies over again in the event
|
731
|
-
/// of eviction or workflow activation failure. Activation failures specifically are only run once,
|
732
|
-
/// since they clearly can't be returned every time we replay the workflow, or it could never
|
733
|
-
/// proceed
|
734
|
-
pub(crate) async fn poll_and_reply<'a>(
|
735
|
-
worker: &'a Worker,
|
736
|
-
eviction_mode: WorkflowCachingPolicy,
|
737
|
-
expect_and_reply: &'a [AsserterWithReply<'a>],
|
738
|
-
) {
|
739
|
-
poll_and_reply_clears_outstanding_evicts(worker, None, eviction_mode, expect_and_reply).await;
|
740
|
-
}
|
741
|
-
|
742
|
-
pub(crate) async fn poll_and_reply_clears_outstanding_evicts<'a>(
|
743
|
-
worker: &'a Worker,
|
744
|
-
outstanding_map: Option<OutstandingWFTMap>,
|
745
|
-
eviction_mode: WorkflowCachingPolicy,
|
746
|
-
expect_and_reply: &'a [AsserterWithReply<'a>],
|
747
|
-
) {
|
748
|
-
let mut evictions = 0;
|
749
|
-
let expected_evictions = expect_and_reply.len() - 1;
|
750
|
-
let mut executed_failures = HashSet::new();
|
751
|
-
let expected_fail_count = expect_and_reply
|
752
|
-
.iter()
|
753
|
-
.filter(|(_, reply)| !reply.is_success())
|
754
|
-
.count();
|
755
|
-
|
756
|
-
'outer: loop {
|
757
|
-
let expect_iter = expect_and_reply.iter();
|
758
|
-
|
759
|
-
for (i, interaction) in expect_iter.enumerate() {
|
760
|
-
let (asserter, reply) = interaction;
|
761
|
-
let complete_is_failure = !reply.is_success();
|
762
|
-
// Only send activation failures once
|
763
|
-
if executed_failures.contains(&i) {
|
764
|
-
continue;
|
765
|
-
}
|
766
|
-
|
767
|
-
let mut res = worker.poll_workflow_activation().await.unwrap();
|
768
|
-
let contains_eviction = res.eviction_index();
|
769
|
-
|
770
|
-
let mut do_release = false;
|
771
|
-
if let Some(eviction_job_ix) = contains_eviction {
|
772
|
-
// If the job list has an eviction, make sure it was the last item in the list
|
773
|
-
// then remove it, since in the tests we don't explicitly specify evict assertions
|
774
|
-
assert_eq!(
|
775
|
-
eviction_job_ix,
|
776
|
-
res.jobs.len() - 1,
|
777
|
-
"Eviction job was not last job in job list"
|
778
|
-
);
|
779
|
-
res.jobs.remove(eviction_job_ix);
|
780
|
-
do_release = true;
|
781
|
-
}
|
782
|
-
|
783
|
-
// TODO: Can remove this if?
|
784
|
-
if !res.jobs.is_empty() {
|
785
|
-
asserter(&res);
|
786
|
-
}
|
787
|
-
|
788
|
-
let reply = if res.jobs.is_empty() {
|
789
|
-
// Just an eviction
|
790
|
-
WorkflowActivationCompletion::empty(res.run_id.clone())
|
791
|
-
} else {
|
792
|
-
// Eviction plus some work, we still want to issue the reply
|
793
|
-
WorkflowActivationCompletion {
|
794
|
-
run_id: res.run_id.clone(),
|
795
|
-
status: Some(reply.clone()),
|
796
|
-
}
|
797
|
-
};
|
798
|
-
|
799
|
-
let ends_execution = reply.has_execution_ending();
|
800
|
-
|
801
|
-
worker.complete_workflow_activation(reply).await.unwrap();
|
802
|
-
|
803
|
-
if do_release {
|
804
|
-
if let Some(omap) = outstanding_map.as_ref() {
|
805
|
-
omap.release_run(&res.run_id);
|
806
|
-
}
|
807
|
-
}
|
808
|
-
// Restart assertions from the beginning if it was an eviction (and workflow execution
|
809
|
-
// isn't over)
|
810
|
-
if contains_eviction.is_some() && !ends_execution {
|
811
|
-
continue 'outer;
|
812
|
-
}
|
813
|
-
|
814
|
-
if complete_is_failure {
|
815
|
-
executed_failures.insert(i);
|
816
|
-
}
|
817
|
-
|
818
|
-
match eviction_mode {
|
819
|
-
WorkflowCachingPolicy::NonSticky => (),
|
820
|
-
WorkflowCachingPolicy::AfterEveryReply => {
|
821
|
-
if evictions < expected_evictions {
|
822
|
-
worker.request_workflow_eviction(&res.run_id);
|
823
|
-
evictions += 1;
|
824
|
-
}
|
825
|
-
}
|
826
|
-
}
|
827
|
-
}
|
828
|
-
|
829
|
-
break;
|
830
|
-
}
|
831
|
-
|
832
|
-
assert_eq!(expected_fail_count, executed_failures.len());
|
833
|
-
assert_eq!(worker.outstanding_workflow_tasks().await, 0);
|
834
|
-
}
|
835
|
-
|
836
|
-
pub(crate) fn gen_assert_and_reply(
|
837
|
-
asserter: &dyn Fn(&WorkflowActivation),
|
838
|
-
reply_commands: Vec<workflow_command::Variant>,
|
839
|
-
) -> AsserterWithReply<'_> {
|
840
|
-
(
|
841
|
-
asserter,
|
842
|
-
workflow_completion::Success::from_variants(reply_commands).into(),
|
843
|
-
)
|
844
|
-
}
|
845
|
-
|
846
|
-
pub(crate) fn gen_assert_and_fail(asserter: &dyn Fn(&WorkflowActivation)) -> AsserterWithReply<'_> {
|
847
|
-
(
|
848
|
-
asserter,
|
849
|
-
workflow_completion::Failure {
|
850
|
-
failure: Some(Failure {
|
851
|
-
message: "Intentional test failure".to_string(),
|
852
|
-
..Default::default()
|
853
|
-
}),
|
854
|
-
..Default::default()
|
855
|
-
}
|
856
|
-
.into(),
|
857
|
-
)
|
858
|
-
}
|
859
|
-
|
860
|
-
/// Generate asserts for [poll_and_reply] by passing patterns to match against the job list
|
861
|
-
#[macro_export]
|
862
|
-
macro_rules! job_assert {
|
863
|
-
($($pat:pat),+) => {
|
864
|
-
|res| {
|
865
|
-
assert_matches!(
|
866
|
-
res.jobs.as_slice(),
|
867
|
-
[$(WorkflowActivationJob {
|
868
|
-
variant: Some($pat),
|
869
|
-
}),+]
|
870
|
-
);
|
871
|
-
}
|
872
|
-
};
|
873
|
-
}
|
874
|
-
|
875
|
-
/// Forcibly drive a future a number of times, enforcing it is always returning Pending. This is
|
876
|
-
/// useful for ensuring some future has proceeded "enough" before racing it against another future.
|
877
|
-
#[macro_export]
|
878
|
-
macro_rules! advance_fut {
|
879
|
-
($fut:ident) => {
|
880
|
-
::futures::pin_mut!($fut);
|
881
|
-
{
|
882
|
-
let waker = ::futures::task::noop_waker();
|
883
|
-
let mut cx = core::task::Context::from_waker(&waker);
|
884
|
-
for _ in 0..10 {
|
885
|
-
assert_matches!($fut.poll_unpin(&mut cx), core::task::Poll::Pending);
|
886
|
-
::tokio::task::yield_now().await;
|
887
|
-
}
|
888
|
-
}
|
889
|
-
};
|
890
|
-
}
|
891
|
-
|
892
|
-
#[macro_export]
|
893
|
-
macro_rules! prost_dur {
|
894
|
-
($dur_call:ident $args:tt) => {
|
895
|
-
std::time::Duration::$dur_call$args
|
896
|
-
.try_into()
|
897
|
-
.expect("test duration fits")
|
898
|
-
};
|
899
|
-
}
|
900
|
-
|
901
|
-
#[async_trait]
|
902
|
-
pub(crate) trait WorkerExt {
|
903
|
-
/// Initiate shutdown, drain the pollers, and wait for shutdown to complete.
|
904
|
-
async fn drain_pollers_and_shutdown(self);
|
905
|
-
/// Initiate shutdown, drain the *activity* poller, and wait for shutdown to complete.
|
906
|
-
/// Takes a ref because of that one test that needs it.
|
907
|
-
async fn drain_activity_poller_and_shutdown(&self);
|
908
|
-
}
|
909
|
-
|
910
|
-
#[async_trait]
|
911
|
-
impl WorkerExt for Worker {
|
912
|
-
async fn drain_pollers_and_shutdown(self) {
|
913
|
-
self.initiate_shutdown();
|
914
|
-
tokio::join!(
|
915
|
-
async {
|
916
|
-
assert_matches!(
|
917
|
-
self.poll_activity_task().await.unwrap_err(),
|
918
|
-
PollActivityError::ShutDown
|
919
|
-
);
|
920
|
-
},
|
921
|
-
async {
|
922
|
-
assert_matches!(
|
923
|
-
self.poll_workflow_activation().await.unwrap_err(),
|
924
|
-
PollWfError::ShutDown
|
925
|
-
);
|
926
|
-
}
|
927
|
-
);
|
928
|
-
self.finalize_shutdown().await;
|
929
|
-
}
|
930
|
-
|
931
|
-
async fn drain_activity_poller_and_shutdown(&self) {
|
932
|
-
self.initiate_shutdown();
|
933
|
-
assert_matches!(
|
934
|
-
self.poll_activity_task().await.unwrap_err(),
|
935
|
-
PollActivityError::ShutDown
|
936
|
-
);
|
937
|
-
self.shutdown().await;
|
938
|
-
}
|
939
|
-
}
|