|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'test' |
| 4 | +require 'eager_workflow_start/eager_workflow' |
| 5 | +require 'securerandom' |
| 6 | +require 'temporalio/testing' |
| 7 | +require 'temporalio/worker' |
| 8 | + |
| 9 | +module EagerWorkflowStart |
| 10 | + class EagerWorkflowTest < Test |
| 11 | + def test_workflow |
| 12 | + # Run test server until completion of the block |
| 13 | + Temporalio::Testing::WorkflowEnvironment.start_local( |
| 14 | + dev_server_download_version: 'latest' |
| 15 | + ) do |env| |
| 16 | + # Run worker until completion of the block |
| 17 | + worker = Temporalio::Worker.new( |
| 18 | + client: env.client, |
| 19 | + task_queue: "tq-#{SecureRandom.uuid}", |
| 20 | + activities: [GreetingActivity], |
| 21 | + workflows: [EagerWorkflow] |
| 22 | + ) |
| 23 | + worker.run do |
| 24 | + # Start workflow with eager start |
| 25 | + handle = env.client.start_workflow( |
| 26 | + EagerWorkflow, |
| 27 | + 'Temporal', |
| 28 | + id: "wf-#{SecureRandom.uuid}", |
| 29 | + task_queue: worker.task_queue, |
| 30 | + request_eager_start: true |
| 31 | + ) |
| 32 | + assert_equal('Hello, Temporal!', handle.result) |
| 33 | + |
| 34 | + # Verify workflow was eagerly executed |
| 35 | + started_event = handle.fetch_history_events.find(&:workflow_execution_started_event_attributes) |
| 36 | + assert(started_event.workflow_execution_started_event_attributes.eager_execution_accepted) |
| 37 | + end |
| 38 | + end |
| 39 | + end |
| 40 | + end |
| 41 | +end |
0 commit comments