|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'test' |
| 4 | +require 'securerandom' |
| 5 | +require 'temporalio/testing' |
| 6 | +require 'temporalio/worker' |
| 7 | +require 'polling/periodic_sequence/greeting_workflow' |
| 8 | +require 'polling/periodic_sequence/compose_greeting_activity' |
| 9 | +require 'polling/periodic_sequence/test_service' |
| 10 | + |
| 11 | +module Polling |
| 12 | + module PeriodicSequence |
| 13 | + class GreetingWorkflowTest < Test |
| 14 | + def test_workflow_completes_after_polling |
| 15 | + task_queue = "tq-#{SecureRandom.uuid}" |
| 16 | + |
| 17 | + Temporalio::Testing::WorkflowEnvironment.start_time_skipping do |env| |
| 18 | + worker = Temporalio::Worker.new( |
| 19 | + client: env.client, |
| 20 | + task_queue: task_queue, |
| 21 | + activities: [Polling::PeriodicSequence::ComposeGreetingActivity], |
| 22 | + workflows: [Polling::PeriodicSequence::GreetingWorkflow, Polling::PeriodicSequence::ChildWorkflow] |
| 23 | + ) |
| 24 | + |
| 25 | + handle = env.client.start_workflow( |
| 26 | + Polling::PeriodicSequence::GreetingWorkflow, |
| 27 | + 'Temporal', |
| 28 | + id: "wf-#{SecureRandom.uuid}", |
| 29 | + task_queue: task_queue |
| 30 | + ) |
| 31 | + |
| 32 | + worker.run do |
| 33 | + env.sleep(5) |
| 34 | + # Wait for the workflow to complete and assert its result |
| 35 | + result = handle.result |
| 36 | + assert_equal 'Hello, Temporal!', result |
| 37 | + end |
| 38 | + |
| 39 | + child_started_event = handle.fetch_history_events.filter_map do |e| |
| 40 | + e.child_workflow_execution_started_event_attributes&.workflow_type&.name |
| 41 | + end.first |
| 42 | + assert_equal 'ChildWorkflow', child_started_event |
| 43 | + end |
| 44 | + end |
| 45 | + end |
| 46 | + end |
| 47 | +end |
0 commit comments