diff --git a/features/child_workflow/result/feature.rs b/features/child_workflow/result/feature.rs new file mode 100644 index 00000000..72766286 --- /dev/null +++ b/features/child_workflow/result/feature.rs @@ -0,0 +1,83 @@ +use anyhow::{Result, ensure}; +use std::time::Duration; +use temporalio_client::WorkflowGetResultOptions; +use temporalio_features_harness::{Feature, FeatureContext, async_trait}; +use temporalio_macros::{workflow, workflow_methods}; +use temporalio_sdk::{ + ChildWorkflowOptions, WorkerOptions, WorkflowContext, WorkflowResult, +}; + +const CHILD_WORKFLOW_INPUT: &str = "test"; + +#[workflow] +#[derive(Default)] +pub struct ResultChildWorkflow; + +#[workflow_methods] +impl ResultChildWorkflow { + #[run] + pub async fn run( + _ctx: &mut WorkflowContext, + input: String, + ) -> WorkflowResult { + Ok(input) + } +} + +#[workflow] +#[derive(Default)] +pub struct ResultWorkflow; + +#[workflow_methods] +impl ResultWorkflow { + #[run] + pub async fn run(ctx: &mut WorkflowContext) -> WorkflowResult { + let child = ctx + .start_child_workflow( + ResultChildWorkflow::run, + CHILD_WORKFLOW_INPUT.to_owned(), + ChildWorkflowOptions::builder() + .workflow_id("result-child".to_owned()) + .execution_timeout(Duration::from_secs(600)) + .task_timeout(Duration::from_secs(60)) + .build(), + ) + .await?; + Ok(child.result().await?) + } +} + +struct ResultFeature; + +#[async_trait] +impl Feature for ResultFeature { + fn worker_options(&self, mut worker_options: WorkerOptions) -> Result { + worker_options + .register_workflow::()? + .register_workflow::()?; + Ok(worker_options) + } + + async fn execute(&self, context: FeatureContext) -> Result<()> { + let handle = context + .client + .start_workflow( + ResultWorkflow::run, + (), + context.workflow_start_options(), + ) + .await?; + let result = handle + .get_result(WorkflowGetResultOptions::default()) + .await?; + ensure!( + result == CHILD_WORKFLOW_INPUT, + "unexpected child workflow result: {result}" + ); + Ok(()) + } +} + +pub fn feature() -> impl Feature { + ResultFeature +}